I've just uncovered this subject, here is my insights:
Fast start
- Open LUA
- Start a new test file (let's call it 'my_code.tests.lua').
- Edit 'my_code.tests.lua' (example template below)
--- my_code.tests.lua Code --------------------------------------------
function my_super_function( arg1, arg2 ) return arg1 + arg2 end
require('luaunit')
TestMyStuff = {}
function TestMyStuff:testWithNumbers()
a = 1
b = 2
result = my_super_function( a, b )
assertEquals( type(result), 'number' )
assertEquals( result, 3 )
end
function TestMyStuff:testWithRealNumbers()
a = 1.1
b = 2.2
result = my_super_function( a, b )
assertEquals( type(result), 'number' )
assertEquals( result, 3 )
end
luaUnit:run()
--- Code End -----------------------------------------------------------------------
- Execute the test code.
- Add your tests and assumption checking.
- Fix what's broken.
Understand more