Skip to main content

Gameplay tests

A test plays your game for a few seconds, holding keys and tapping buttons at set times, and checks that the right things happened: the player reached the flag, a coin added 10 to the score, the Play button opened Level 1. It works like a play mode test in Unity's Test Runner.

Save a test for each thing that must keep working. After a change, press Run all and you know at once whether something broke.

Open the tests from ☰ → Play → Tests (on desktop also Scene → Tests…).

Two tests passed, one failed (with the check that failed and its value)
Two tests passed, one failed (with the check that failed and its value)
A test: what the player does, and what must be true
A test: what the player does, and what must be true

Running tests​

ButtonWhat it does
▶ Run allRuns every test, one after another.
▶ Run failedRuns only the tests that failed last time.
▶ on a testRuns that test.

While the tests run, the game plays in the editor (fast, frame by frame), so you can watch. Then the list comes back with a ✓ or ✗ on each test. Tap a test that has run to see each check and the value it found.

Before you publish​

When a project has tests, Publish (and Update) and every Build in the Build panel (Web, Android, Windows, Linux) run them first. If they all pass, it goes on as usual. If one fails, you see which ones and choose Open tests to fix them, or go ahead anyway. The Run before publish / build switch at the top of the Tests panel turns this off for the project.

A test fails when one of its checks is false, or when the game shows a runtime error, a tap misses its button (hidden or covered), or the test sets a variable the game doesn't have.

Record a test by playing​

Tap ⏺ Record. The scene you are editing starts, and you play it as usual: keys, on-screen buttons, the joystick, UI buttons. Press Stop when you are done.

The new test has everything you did as its inputs:

  • Keys you held, at the moments you held them.
  • On-screen buttons as the keys they stand for (Jump → Space), and the joystick as arrow keys, so a test recorded on a phone also runs on a computer.
  • UI buttons you tapped.

Under Suggested are checks for what changed while you played: a variable (Score = 30), the scene (scenename() = "Level 2"), how many of an object are left (Coin.count = 2), and who moved (Player.x > 8). Tap one to add it, or + all.

The test then plays your recording back exactly, frame by frame. Joystick moves come back at full tilt, so a check on how far something moved may need a little room.

Making a test​

Tap + New test, or ✏ on a test to change it.

SettingWhat it is
SceneWhere the game starts. ★ = the start scene, through the loading screen, as a player would start it.
SecondsHow long the test plays (game time, up to 120 s).
InputsWhat the player does. + ⌨ holds a key (or an on-screen button's key) from at for hold seconds. + 👆 taps a UI element at at seconds.
SetVariables set after the first frame (after On start of scene), to start in a certain state: TimeLeft = 2 to test the end of the timer, Lives = 1 to test game over. Global, scene and static event variables all work.
ChecksExpressions that must be true, in the same form as event expressions.

A check is tested:

  • End: when the test ends.
  • At: at a moment (seconds from the start).
  • Always: the whole way through (ten times a second). The first time it is false, the test fails.

Some checks:

CheckMeans
Score >= 10The score reached 10.
Player.x > 20The player got past x = 20.
Coin.count = 0Every coin was picked up.
Lives = 3 with AlwaysThe player never lost a life.
scenename() = "Level 2"The game moved on to Level 2.

Tests are saved in your project, but they are not part of exported or published games.

With Claude​

Through the Claude link, Claude can save tests, run them and read the results. Ask it to save a test for each feature it builds, and to run them all after a change:

  • Save tests for the coins, the timer and the Play button.
  • Run the tests and fix whatever fails.

From the command line​

tge-test.mjs runs a project's tests and checks without the editor on screen: in a build script, on a build server (CI), or for an AI agent that works in a terminal. It needs Node.js 22 or newer and Chrome or Edge on the computer. Nothing else to install.

1. Download it. Save tge-test.mjs next to your project.

2. Save the project as a file. Use ☰ → Backup project (.tge). A project folder (unzipped, or the zip) works too.

3. Run it.

node tge-test.mjs MyGame.tge

It opens the editor in a browser with no window (a fresh browser profile each time, so your own projects are never touched), runs the project checks (event sheets, scripts, scenes) and every saved test, and prints the results:

Project "My game"
PASS Coin pickup (ended in Level 1)
✓ at the end: Score >= 1 → true
FAIL Play button (ended in Title)
✗ at the end: scenename() = "Level 1" → 2 s: false
Checks: No problems found.
FAILED: 1 of 2 tests passed, 0 check errors.

The exit code tells a script how it went: 0 everything passed, 1 a test failed or a check found an error (warnings don't count), 2 the run itself failed (no browser, not a project).

OptionWhat it does
--test <name>Run only this test (repeat it for more).
--no-checksSkip the project checks.
--no-scriptsCheck sheets and scenes but don't type-check scripts.
--jsonPrint the results as JSON.
--browser <path>The Chrome or Edge to use, when it isn't found by itself.
--showShow the browser window while it runs.
--timeout <s>Give up after this many seconds (default 600).

The tests run in the same editor and game as Play, so a test that passes in the Tests panel passes here.