![]() |
VOOZH | about |
GameTest is an automated end-to-end (E2E) testing framework for testing aspects of Minecraft. Each test contains a structure, parameters for how the test gets executed, and optional code to further specify the test behavior.
Test instance can be defined in a datapack by creating a JSON file in the test_instance registry. Players can inspect information about them using a ๐ Image
test instance block. A test instance has the following properties:
There are more configuration available for test instances. For more information on the format, see test instance definition.
In block-based tests, Test blocks are used inside the test structure to control the test logic using redstone signal.
If a race condition occurs, the first test block activated always wins.
Function tests rely on built-in test functions to determine a test's success or failure. They are meant to be used by Mojang internally and by mod developers.
The game provides the GameTest framework interfaces through the net.minecraft.gametest.framework package (Mojang mapping). Mod loaders typically provide their own testing API for developers to use the GameTest framework, there are documentation available for Fabric and NeoForge.
A test function must be registered in the test_function registry to be referenced in the test instance. The [String] function field in the test instance definition should contain the resource location of the test function.
Test environment is a way to group up test instances and give them the right preconditions to run. It can be defined in a datapack by either creating a JSON file in the test_instance registry or directly specified the environment inline with the [NBT Compound / JSON Object] batch field. It can also use the test environment of the vanilla data package minecraft:default, which is empty preconditions.
The /test command exists to execute and manage block-based tests. Some notable sub-commands include:
/test (run|runmultiple) <tests> ... sub-commands can run specific test(s) for a number of times by their identifier./test (runclosest|runthat|runthese) ... sub-commands can run test(s) based on the player's location./test (resetclosest|resetthat|resetthese) sub-commands reset the test structures for any tests./test locate <tests> locates test in loaded chunks.The net.minecraft.gametest.Main entry point is included in server.jar which starts a server, runs all available game tests and then exits. It can be invoked in the command line, such as:
java-DbundlerMainClass="net.minecraft.gametest.Main"-jarserver.jar[<options>]
--help - Shows usage information--packs <path> - Set a folder of datapacks to include in the world
pack.mcmeta file is included--report <path> - Exports results in a junit-like XML report at the given path--tests <selection> - Specify which tests to run with a selection - a wildcard expression matching namespace test instance IDs
--universe <path> - The path to where the test server world will be created
gametestserver--verify <boolean> - Enables test verification
test or testNamespace 100 times for each 90 degree rotation stepfalseThe game will yield the following exit codes depending on the scenario:
| Scenario | Exit code |
|---|---|
| All tests pass | 0 |
| Any test fails | (number of failures) |
| Server shut down without starting tests | -1 |
| Game crashed | 1 |
The GameTest framework can be accessed through the @minecraft/server-gametest module from the Script API. The module must be added as a dependency in the manifest.json. It contains many programming interfaces used for automated testing of any game objects' behaviors and interactions in a controlled testing environment.[1] Developers can use these interfaces for:
A testing environment can be created from a unit test (also called a GameTest), which contains a test function registered from the script, and a reference to a .mcstructure file exists in the behavior pack.[3][4] Users can register a new unit test using GameTest#register(testClassName, testName, testFunction) method with additional builder parameters, such as .maxTicks(ticks) that indicates the test may take amount of ticks to run, .maxAttempts(attempts) which specifies how many attempt the test can run, and more.[4]
After the unit test is registered, it is loaded in the world, and can be run using the /gametest command, referenced by <testClassName>:<testName>. When ran, the game spawns the test structure and calls the test function previously defined in the script. The unit test may succeed or fail depending on the test function, which usually contain instructions for testing behaviors and interactions in the testing environment.
| November 9, 2020 | Henrik Kniberg demonstrated GameTest, a test framework used internally by Mojang, on the Agile with Jimmy YouTube channel. | ||||||
|---|---|---|---|---|---|---|---|
| Java Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.15 | 19w34a | References to GameTest added in the game's code. Most of the framework is stripped, since the rest of the game does not depend on it. | |||||
| 1.17 | 21w13a | GameTest related code is now exposed for mod developers' use because unused parts of code are no longer removed. | |||||
| 1.21.5 | 25w03a | Overhauled the GameTest framework. | |||||
| Introduced for use with data packs. | |||||||
| 1.21.11 | 25w44a | In the game_rules test environment the keys bool_rule and int_rule have been replaced with a single key rules. | |||||
| 26.1 | snap3 | Replaced time_of_day with clock_time. | |||||
Added a new required field clock: world clock ID, the clock within which to set time (from the existing time field). | |||||||
| snap11 | Added timeline_attributes definitions to set any number of timelines. | ||||||
| 26.2 | snap5 | Added minecraft:difficulty. | |||||
| Bedrock Edition | |||||||
|---|---|---|---|---|---|---|---|
| 1.16.210 | beta 1.16.210.60 | Added GameTest framework. | |||||
| Minecraft: Bedrock Edition | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Editions |
| ||||||||
| Development |
| ||||||||
| Technical |
| ||||||||
| Multiplayer | |||||||||
| Exclusive features |
| ||||||||
| Removed | |||||||||