TestApi.lua
The methods and switches used to write test classes :
- differs
-
Test whether a function does not give the expected result.
local test = require('btd.lua.testapi)
...
TestClass = {}
TestClass:testMethod()
a = {1,2,3}
b = DeepCopy(a)
test.equals(a,b)
b[1] = 5
test.differs(a,b) -- my DeepCopy method works
end
- equals
-
Test wheter a function gives the expected result.
local test = require('btd.lua.testapi)
...
TestClass = {}
TestClass:testMethod()
test.equals(1 + 1,2)
end
For LuaUnit compatibility also known under the synonyms
assertEquals
and assert_Equals
.
local test = require('btd.lua.testapi) -- necessary for error reporting
...
TestClass = {}
TestClass:testMethod()
assertEquals(1 + 1,2)
end
Can also analyse table results, with following remarks :
- tables are equal if :
- Both tables have the same length
- At the same key find the same value
- or if they are equal (__eq operator)
-
The check is recursive, so tables within tables will also
be analysed
- fails
-
Test whether a function throws an (expected) exception.
local test = require('btd.lua.testapi)
...
TestClass = {}
TestClass:testMethod()
test.fails(function() error('error') end)
end
For LuaUnit compatibility also known under the synonyms
assertError
and assert_Error
.
local test = require('btd.lua.testapi) -- necessary for error reporting
...
TestClass = {}
TestClass:testMethod()
assertError(function() error('error') end)
end
- succeeds
-
Test whether a function does not throw an exception.
local test = require('btd.lua.testapi)
...
TestClass = {}
TestClass:testMethod()
test.succeeds(function() end)
end
- wrap
-
Wrap a number of test functions in a test class.
local test = require('btd.lua.testapi)
...
function test1()
assert(1 == 1)
end
...
TestFunction = test.wrap('test1','test2','test3'
For LuaUnit compatibility also known under the synonym
wrapFunctions
.
local test = require('btd.lua.testapi) -- necessary for error reporting
...
function test1()
assert(1 == 1)
end
...
TestFunction = wrapFunctions('test1','test2','test3'