Running Tests

Overview

Testing in Godot using the GUT (Godot Unit Testing) framework can be done in multiple ways: through the Godot editor using the tests.tscn scene or the GUT tab, and via command line locally and through Github Action/CI. Ensuring that tests pass is mandatory before merging changes into the main branch.

Running Tests in the Godot Editor

Using tests.tscn

  1. Open the Test Scene: Navigate to and open the tests.tscn file in your Godot project. This scene is specifically set up to run your GUT tests.

  2. Run the Scene: Press the "Play Scene" button (F6 by default) to execute the tests. GUT will run all the tests in your project and display the results in the output console.

tests.tscn file

Using the GUT Tab

  1. Open the GUT Tab: In the Godot editor, find the GUT tab, usually located at the bottom panel alongside the "Output" and "Debugger" tabs.

  2. Run the Tests: Click on the "Run" button in the GUT tab. This will execute all your tests and show the results directly in the GUT panel.

GUT Tab

Running Tests via Command Line for CI

For continuous integration, tests are run automatically whenever a pull request (PR) is made against the main branch. The tests need to pass for the PR to be eligible for merging. The command used in the CI environment is as follows in the root of the project, you can run it too on unix-like terminals:

godot --path $PWD -s addons/gut/gut_cmdln.gd -glog=1

This same script is run as part of the CI build step, as shown below.

CI Build

Defined in this main.yml file if you're wondering where:

.github/workflows/main.yml

Conclusion

Running GUT tests regularly, both locally in the Godot editor and through CI in the development workflow, is crucial for maintaining high-quality, stable code. Ensure that your tests cover the necessary aspects of your game to leverage the full benefits of automated testing.