DefTest - Writing and running unit tests in Defold

I have received a couple of questions on how to write and run unit tests in Defold. Unit testing your game logic in Defold is not that much different from unit testing normal Lua code but if you do not have much experience with unit testing it might be difficult to know where to start and which unit testing framework to use. Lua has many different unit testing frameworks and I decided to create a library project and examples based on the Telescope framework. You can check out the project and read more about how to use it here:

21 Likes

I’m using this library and it works as I would expect it to in Defold. I also use VScode to edit all my code. Keywords that telescope uses (context, test, assert_equals, etc.) show an “undefined global …” The library still works from defold or code. Is there a way I can get the API reference for telescope in VScode, the same way DefoldKit integrates defold’s API into code?

You can add a file with code annotations for these globals and VS Code and the LSP should be able to pick these up.

I’ve added a deftest.lua file similar to those in .defold/api in .deftest/api with the —@meta at the top with function definitions, and VScode picks it up. Thanks for the tip!

1 Like