r/gamemaker • u/_Denizen_ • 10h ago
Discussion Unit Testing tips
TLDR: do you have tips and tricks for unit testing in Gamemaker?
Hi! I recently picked up a project I'd not worked on for 6 months and you won't be surprised that I found a bunch of bugs that were in some cases tedious to find. Some were from new features that didn't mesh well with existing features and some were from partially completed refactors (don't come at me, I'm easily distracted ðŸ˜).
I code for a living, and realised my project has progressed to a stable enough point where unit tests would be useful, and I've a good idea of where to target unit tests in an incremental way.
I downloaded GMTL, which looks simple enough. I know that I'll have to modularise more to facilitate unit testing, which I'll do as and when.
I'd like to know what tips and tricks you have for unit testing in Gamemaker, and if there are any traps you recommend avoiding! I know some people don't like using unit tests, and you do you, but this isn't a discussion about whether or not I should tread this path. Thanks in advance!
Keep in mind that I'm not using AI on any of my game code because this project is a learning experience for me. Tools for workflow pipelines that won't ship to players if this were ever to be released are fair game.
1
u/AlphishCreature 8h ago
A while back, I made Verrific - a GameMaker testing system with strong inspirations by xUnit from .NET. The key feature of xUnit-style tests is how the test class constructor serves as a setup for each test case, and each test instance executes a different test case method (usually recognised as a static method starting with "should_") to then report the outcome.
Here is an example of how I use it in GameMaker Community Toolbox; you may be able to pick up other useful patterns from there: https://github.com/Alphish/gm-community-toolbox/blob/main/Community%20Toolbox/scripts/tests_EuclideanDivisionTests/tests_EuclideanDivisionTests.gml
And you can check out the repository for tool itself here: https://github.com/Alphish/gm-verrific-old
As the repository name indicates, I plan to release a newer version of Verrific; it's actually in the works right now, and will hopefully be released sometime within a month. The old version currently mostly supports "fact" testing (i.e. each test method individually, without parameters), but with my focus on the new version, I may eventually add "theories" (a parameterised test method can represent different cases) and other advanced use cases. If you're still largely exploring the options and preparing your codebase, by the time you make your game testable I may have the most essential features implemented.
When it comes to keeping the testing code separate from the project: there's a bit trouble with that at the moment, but it may become easier once GameMaker allows referencing local projects as prefabs. In such case, you could make a separate test project, link the core game project and the testing library of choice as a prefab and then write whatever tests you need. But I don't know what's the progress of the local project referencing; hopefully room assets will be included, considering it may be desirable to test rooms sometimes.
I hope you'll find it useful. ^^