Unit testing for LOVE games, powered by Lunatest.
- Simple setup with zero dependencies
- Run tests via the command line
- Create tests quickly
Download the latest release and unzip it into the same folder as your
main.lua file.
In main.lua, add the following lines to your love.load function. Add the
function if you don't have it already.
local lovetest = require "test/lovetest"
function love.load(arg)
-- Check for the testing command line flags
if lovetest.detect(arg) then
-- Run the tests
lovetest.run()
end
endUsing the command line, you can now run your unit tests
love path/to/game --test
Tests are just lua scripts stored in the test directory. Their filename must
begin with test_. Each unit test function's name must also begin with test_.
We're going to test that addition works (dumb, I know). Create a file inside
the test directory named test_math.lua with the following contents.
function test_addition()
assert_equal(2 + 2, 4)
end
function test_subtraction()
assert_equal(2 - 2, 0)
endFor more information on writing tests, read the Lunatest documentation and examples.