Unit Testing game/lib

I’m new to unit testing and have some problems with it, can someone please help me to set up environment to test my lib?
@james

We use LuaUnit to test the SDK and firmware in the simulator and device. If you want to use it you can do the following:

IMPORTANT: we’re using luaunit 3.2.1. YMMV with other version.

  1. copy the luaunit source into your source folder

  2. Add these patch files to the lauunit source folder.
    panic-luaunit.zip (22.2 KB)

  3. In your main.lua add the following to the top

import 'luaunit/playdate_luaunit_fix'
import 'luaunit/luaunit'
  1. Import your unit tests

  2. run luaunit with the following:

-- turns off updating
playdate.stop()

-- when outputting a table, include a table address
luaunit.PRINT_TABLE_REF_IN_ERROR_MSG = true

-- process the command line args (if any)
local testOutputFilename = "test_output"
local outputType = "text"
local luaunit_args = {'--output', 'text', '--verbose', '-r'}

-- run the tests
local returnValue = luaunit.LuaUnit.run(table.unpack(luaunit_args))

print("unit test return value = "..returnValue)

CAVEATS: I haven’t tested these instructions directly. They’re simply taken from what we’re doing with our own code.

6 Likes

That thank you for the detailed answer!

Hi Whitebrim, did you get this working? I'm pretty new to lua (and the playdate itself!) but would like to warm embrace of unit tests to help play with stuff :smile:.

You can find my code here: AnimatedSprite/tests/unit-tests/source at master · Whitebrim/AnimatedSprite · GitHub

Ah nice!

I got something working after much mashing my head off the wall, but I like your solution for setup and teardown so might steal it (my over complex solution looks like this currently playdate/Player-Test.lua at 5e0d925426ce7ae7e67f179a9373330a95213818 · neil-armstrong-fig/playdate · GitHub).

Will have a closer look at yours later, thanks!

1 Like