Godot: testing¶
Automated tests for Godot projects with GUT or gdUnit4, the design that makes code testable, keeping tests out of exports, and running tests in CI. The engine-independent testing rules are in Testing and delivery.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 6 GUT documentation (GUT, Godot Unit Test): writing tests in GDScript, doubles, stubs and spies, awaiting and simulating frames, memory checks, and the command line.
- 6 gdUnit4 documentation (gdUnit4): tests in GDScript and C#, fluent assertions, mocks and spies, the Scene Runner, orphan node detection, and the command-line tool and GitHub Action for CI.
Key rules¶
- 7
GODOT-14Write automated tests with GUT or gdUnit4, and run them headless in CI on every change. (GUT, Command line, gdUnit4, Continuous integration, Godot, Command line tutorial) - 7
GODOT-37Unit-test game logic in isolation, inRefCountedclasses and other scripts that you can create withnew(), and test whole scenes in integration tests with gdUnit4's Scene Runner or GUT'ssimulate()and input sender, for behaviour that spans frames or depends on input. Keeping that logic out of nodes isGODOT-8in code architecture. (gdUnit4, Unit testing, Integration testing, Scene Runner, GUT, Simulate, Mocking Input) - 6
GODOT-38Let the code under test receive its dependencies, asGODOT-3describes for scenes, so that tests can replace them with GUT doubles and stubs or gdUnit4 mocks and spies. GUT's doubles leave out native engine methods by default, and gdUnit4's mocks work only for GDScript, so use a .NET mocking library such as Moq in C#. (Godot, Scene organization, GUT, Doubles, gdUnit4, Mocking) - 6
GODOT-39Keep tests and the test framework out of release exports: put tests in their own folder, such asres://test/, and add it and the framework's addon folder (addons/gut/*oraddons/gdunit4/*) to the exclude filter of every export preset. gdUnit4 isn't meant for production builds, and exporting with it installed can crash the export. (gdUnit4, Export failures with the plugin installed, GUT, Install, Godot, Exporting projects: resource options)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 5 GUT command line: runs the tests outside the editor and returns 1 when any test fails. It can also export JUnit XML results. Checks
GODOT-14. - 5 gdUnit4 command line tool: runs test suites outside the editor, returns 100 on test failures, and writes HTML and JUnit reports. A GitHub Action wraps it for CI. Checks
GODOT-14.