Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Godot Testing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tipoli5890-godot-testing)
---
name: godot-testing
description: >-
Godot GDScript unit tests, headless: a runner with no add-on, assertions, errors caught per
test, CI exit codes; GUT and gdUnit4 as options.
---
# godot-testing — unit tests with no add-on
A `SceneTree` script can load test files, call their `test_` methods and exit non-zero on a
failure; nothing has to be installed.
## Load what the situation needs
| The situation | Read |
|---|---|
| "Add tests", "test this rule", a first test in a project | *Start* below, then `templates/test_route_math.gd` |
| How tests are found and called; the checker; async tests; what PASS, FAIL and ERROR mean | `reference/runner.md` |
| A test run in CI; an exit code you need to branch on; class_name not found in tests | `reference/runner.md` → "In CI", and `scripts/run_tests.py` |
| A test that hangs; `assert()` that freezes a script | `reference/runner.md` → "Two ways a test can hang" |
| GUT or gdUnit4: what they add, using one safely | `reference/addons.md` |
| Whether the whole change works (import, load, scenes) | `godot-verify` |
| A moment of the game played through input, a timeline | `godot-play-harness` |
| Typed GDScript, warnings raised to errors, signals and await | `godot-gdscript` |
## Start
1. Copy `resources/run_tests.gd` and `resources/test_case.gd` into `res://tests/`.
2. Copy `templates/test_route_math.gd` there and point its `preload` at the script under test
(`templates/route_math.gd` is the example it tests).
3. Run it:
```bash
GODOT_BIN=/path/to/Godot python3 scripts/run_tests.py path/to/project
```
```
run tests: exit 1, 0.1s
FAIL res://tests/test_bag.gd::test_bag_capacity: FAIL deliberately wrong: got 4, want 5
run_tests: FAIL 1 problem; 4 passed, 1 failed, 0 errors; 5 tests in 2 files
```
| Exit | Verdict | When |
|---|---|---|
| 0 | `PASS` | `TESTS_DONE` says every test passed, at least one ran, and no marker appeared outside a test |
| 2 | `FAIL` | a failed check, an error inside a test, a test file that does not load, zero tests, or an error outside any test (an autoload at startup, a node leaked at exit) |
| 3 | `UNVERIFIED` | a timeout (the hung test is named), no `TESTS_DONE` line, counts that disagree, no binary |
| 1 | `refused` / usage | no `project.godot`, no runner at `--runner`, a bad flag |
| Flag | Effect |
|---|---|
| `--godot PATH` | the binary; default `$GODOT_BIN`; never guessed |
| `--runner res://...` | where `run_tests.gd` sits (default `res://tests/run_tests.gd`) |
| `--dir res://...` | the folder searched for `test_*.gd` (default `res://tests`) |
| `--match TEXT` | only tests whose `path::name` contains it |
| `--frames N` | each test's frame budget for awaiting (default 600) |
| `--import auto\|always\|never` | `--import` first; auto when a `class_name` needs the class cache |
| `--timeout S` / `--backstop N` | wall clock per run (300) / `--quit-after` (100000) |
| `--fixed-fps N` | one physics tick per frame, no real-time wait (default 60; 0 real time) |
| `--allow-warnings` | warnings outside tests become `NOTE` lines |
The runner also runs by itself, with no Python: `-s res://tests/run_tests.gd -- res://tests`,
then require the `TESTS_DONE` line (`reference/runner.md`).
## A test file
```gdscript
extends RefCounted
const RouteMath = preload("route_math.gd")
func test_eta_divides_distance_by_speed(t: RefCounted) -> void:
t.check_eq(RouteMath.eta_seconds(100.0, 4.0), 25.0, "100 m at 4 m/s")
func test_zero_speed_never_arrives(t: RefCounted) -> void:
t.check(is_inf(RouteMath.eta_seconds(10.0, 0.0)), "zero speed gives INF")
```
Each `test_` method gets `t`, the checker: `check`, `check_eq`, `check_near`, `fail`, and for
tests that need the tree, `await t.frames(n)`, `t.add(node)` (freed after the test) and `t.tree`.
Checks record and return, so a test lists every broken expectation. A runtime error, a failed
`assert()` or a `push_error()` inside a test makes that test an ERROR, and the run goes on.
## What to test here, and what not
- **Rules and data, without nodes.** Arithmetic, state machines, inventories, save-file parsing,
level data: a `RefCounted` script with static functions, or a `Resource`, tested directly.
This is where unit tests pay; a rule that only exists inside a node's `_process` is a rule
that cannot be tested. Move it out.
- **A little of the tree**, with `t.add` and `await t.frames`: a node enters the tree, a signal
fires. Keep it small.
- **Not the game played through.** Input, cameras, a level reached and walked: that is a journey,
`godot-play-harness`. Whether every script and scene loads: `godot-verify`.
## Discipline
- **The exit code is not the verdict.** Godot exits 0 after a parse error in a test file; the
runner's own `quit(1)` is only reached if the runner gets that far. Require `TESTS_DONE`.
- **Zero tests is a failure.** A misspelt folder or a `--match` that matches nothing runs no
test and would otherwise look green.
- **A wall clock and a backstop on every run.** A test that never yields can only be ended from
outside; an error before `quit()` leaves the tree running (`godot-verify` →
`reference/timeouts.md`).
- **Import first when tests touch `class_name`.** Without the class cache the test file does not
load, which reads as a broken test rather than a missing step.
- **Free what a test creates**, or create it with `t.add`. A leaked node prints a warning at exit,
and the run fails on it.
- **Name tests for the rule** (`test_zero_speed_never_arrives`), so a FAIL line reads as the
broken rule.
## Scope — what this skill does NOT do
| Not here | Go to |
|---|---|
| The verdict on a whole change: import, load, scenes | `godot-verify` |
| Journeys, situations, input from a script, timelines | `godot-play-harness` |
| GDScript itself: typing, warnings, signals, await | `godot-gdscript` |
| Flags and running Godot from a terminal | `godot-cli` |