Package net.fabricmc.fabric.api.client.gametest.v1


@Experimental package net.fabricmc.fabric.api.client.gametest.v1
Provides support for client gametests. To register a client gametest, add an entry to the fabric-client-gametest entrypoint in your fabric.mod.json. Your gametest class should implement FabricClientGameTest.

Lifecycle

Client gametests are run sequentially. When a gametest ends, the game will be returned to the title screen. When all gametests have been run, the game will be closed.

Threading

Client gametests run on the client gametest thread. Use the functions inside ClientGameTestContext and other test helper classes to run code on the correct thread. Exceptions are transparently rethrown on the test thread, and their stack traces are mutated to include the async stack trace, to make them easy to track. You can disable this behavior by setting the fabric.client.gametest.disableJoinAsyncStackTraces system property.

The game remains paused unless you explicitly unpause it using various waiting functions such as ClientGameTestContext.waitTick().

A few changes have been made to how the vanilla game threads run, to make tests more reproducible. Notably, there is exactly one server tick per client tick while a server is running (singleplayer or multiplayer). On singleplayer, packets will always arrive on a consistent tick.

Default settings

The client gametest API adjusts some default settings, usually for consistency of tests. These settings can always be changed back to the default value or a different value inside a gametest.

Game options

Setting name Gametest default Vanilla default Reason
Tutorial step NONE MOVEMENT Consistency of tests
Cloud render mode OFF FANCY Consistency of tests
Onboard accessibility false true Would cause the game test runner to have to click through the onboard accessibility prompt
View distance 5 10 Speeds up loading of chunks, especially for functions such as TestClientWorldContext.waitForChunksRender()
Music volume 0.0 1.0 The game music is annoying while running gametests

World creation options

These adjusted defaults only apply if the world builder's consistent settings have not been set to false.
Setting name Gametest default Vanilla default Reason
World type FLAT DEFAULT Creates cleaner test cases
Seed 1 Random value Consistency of tests
Generate structures false true Consistency of tests and creates cleaner tests
Do daylight cycle false true Consistency of tests
Do weather cycle false true Consistency of tests
Do mob spawning false true Consistency of tests

Dedicated server properties

Setting name Gametest default Vanilla default Reason
online-mode false true Allows the gametest client to connect to the dedicated server without being logged in to a Minecraft account
sync-chunk-writes true on Windows, false on other operating systems true Causes world saving and closing to be extremely slow (on the order of many seconds to minutes) on Unix systems. The vanilla default is set correctly in singleplayer but not on dedicated servers.
spawn-protection 0 16 Spawn protection prevents non-opped players from modifying the world within a certain radius of the world spawn point, a likely source of confusion when writing gametests
max-players 1 20 Stops other players from joining the server and interfering with the test
  • Interfaces
    Class
    Description
    Context for a client gametest containing various helpful functions and functions to access the game.
    The fabric-client-gametest entrypoint interface.
    Context for a client gametest containing various helpful functions while a client world is open.
    Context for a client gametest containing various helpful functions while an in-process dedicated server is running.
    The client gametest input handler used to simulate inputs to the client.
    Options to customize a screenshot.
    Context for a connection to a dedicated server containing various helpful functions while the connection is alive.
    Context for a client gametest containing various helpful functions while a server (integrated or dedicated) is running.
    Context for a client gametest containing various helpful functions while a singleplayer game is open.
    A builder used for creating singleplayer worlds and dedicated servers.
    A handle for a singleplayer world save.