Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:GameTest: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
SyncBot (talk | contribs)
Sync: updated from Minecraft
Line 1: Line 1:
{{MC/Redirect|Test}}
{{redirect|Test}}
{{MC/Redirect|Gametest|the command|Commands/gametest}}
{{redirect|Gametest|the command|Commands/gametest}}
'''GameTest''' is an automated {{MC/Wikipedia|end-to-end testing|end-to-end (E2E) testing}} framework for {{MC/Wikipedia|Software testing|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.
'''GameTest''' is an automated {{wikipedia|end-to-end testing|end-to-end (E2E) testing}} framework for {{wikipedia|Software testing|testing}} aspects of ''[[Minecraft:Minecraft]]''. Each test contains a structure, parameters for how the test gets executed, and optional code to further specify the test behavior.


== ''Java Edition'' ==
== ''Java Edition'' ==
Line 7: Line 7:
[[File:Test instance block UI.png|thumb|400px|UI of test instance block]]
[[File:Test instance block UI.png|thumb|400px|UI of test instance block]]


Test instance can be defined in a datapack by creating a [[Minecraft:JSON]] file in the {{MC/Cd|test_instance}} registry. Players can inspect information about them using a {{MC/Blocklink|test instance block}}. A test instance has the following properties:
Test instance can be defined in a datapack by creating a [[Minecraft:JSON]] file in the {{cd|test_instance}} registry. Players can inspect information about them using a {{BlockLink|test instance block}}. A test instance has the following properties:


* It belongs to a [[#Test environment|test environment]], which groups the test and further specifies the environment in which the test is run in. ({{MC/Nbt|compound}}{{MC/Nbt|string|environment}})
* It belongs to a [[#Test environment|test environment]], which groups the test and further specifies the environment in which the test is run in. ({{nbt|compound}}{{nbt|string|environment}})
* It is associated with a {{MC/Nbt|string|structure}}, which should contain all the blocks and entities it needs to be run. The structure can be easily altered with the test instance block.
* It is associated with a {{nbt|string|structure}}, which should contain all the blocks and entities it needs to be run. The structure can be easily altered with the test instance block.
* It can either be a block-based test or a function test. More information is available below.
* It can either be a block-based test or a function test. More information is available below.


There are more configuration available for test instances. For more information on the format, see test instance definition.
There are more configuration available for test instances. For more information on the format, see [[Minecraft:test instance definition]].


==== Block-based ====
==== Block-based ====
In block-based tests, Test blocks are used inside the test structure to control the test logic using redstone signal.
In block-based tests, [[Minecraft:Test block]]s are used inside the test structure to control the test logic using [[Minecraft:redstone signal]].


* {{MC/Blocksprite|test-block-start}} '''Start''': A redstone pulse is triggered when the test starts.
* {{BlockSprite|test-block-start}} '''Start''': A [[Minecraft:redstone pulse]] is triggered when the test starts.
* {{MC/Blocksprite|test-block-log}} '''Log''': Logs a message to the log file when powered by redstone.
* {{BlockSprite|test-block-log}} '''Log''': Logs a message to the log file when powered by redstone.
* {{MC/Blocksprite|test-block-fail}} '''Fail''': Fails the test when powered by redstone.
* {{BlockSprite|test-block-fail}} '''Fail''': Fails the test when powered by redstone.
* {{MC/Blocksprite|test-block-accept}} '''Accept''': Completes the test when powered by redstone.
* {{BlockSprite|test-block-accept}} '''Accept''': Completes the test when powered by redstone.


If a race condition occurs, the first test block activated always wins.
If a race condition occurs, the first test block activated always wins.
Line 28: Line 28:
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 [[Minecraft:mod]] developers.
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 [[Minecraft:mod]] developers.


The game provides the GameTest framework interfaces through the <code>net.minecraft.gametest.framework</code> package (Mojang mapping). Mod loaders can use these to provide their own API for developers to use the GameTest framework – please refer to the respective documentation for [https://docs.fabricmc.net/develop/automatic-testing#game-tests Fabric] and [https://docs.neoforged.net/docs/misc/gametest NeoForge] for more information.
The game provides the GameTest framework interfaces through the <code>net.minecraft.gametest.framework</code> package ([[Minecraft:Obfuscation map|Mojang mapping]]). [[Minecraft:Mod loader]]s typically to provide their own testing API for developers to use the GameTest framework, there are documentation available for [https://docs.fabricmc.net/develop/automatic-testing#game-tests Fabric] and [https://docs.neoforged.net/docs/misc/gametest NeoForge].


A test function must be registered in the <code>test_function</code> registry to be referenced in the test instance. The {{MC/Nbt|string|function}} field in the test instance definition should contain the resource location of the test function.
A test function must be registered in the <code>test_function</code> registry to be referenced in the test instance. The {{nbt|string|function}} field in the test instance definition should contain the [[Minecraft:resource location]] of the test function.


=== Test environment ===
=== Test environment ===
{{MC/Main|Test environment definition}}
{{main|Test environment definition}}


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 [[Minecraft:JSON]] file in the {{MC/Cd|test_instance}} registry or directly specified the environment inline with the {{MC/Nbt|compound|batch}} field. It can also use the test environment of the vanilla data package {{MC/Cd|minecraft:default}}, which is empty preconditions.
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 [[Minecraft:JSON]] file in the {{cd|test_instance}} registry or directly specified the environment inline with the {{nbt|compound|batch}} field. It can also use the test environment of the vanilla data package {{cd|minecraft:default}}, which is empty preconditions.


=== Test command ===
=== Test command ===
{{MC/Main|Commands/test}}
{{main|Commands/test}}
The {{MC/Cmd|test}} command exists to execute and manage block-based tests. Some notable sub-commands include:
The {{cmd|test}} command exists to execute and manage block-based tests. Some notable sub-commands include:


* <code>/test (run|runmultiple) <tests> ...</code> sub-commands can run specific test(s) for a number of times by their identifier.
* <code>/test (run|runmultiple) <tests> ...</code> sub-commands can run specific test(s) for a number of times by their identifier.
Line 54: Line 54:


==== Command-line options ====
==== Command-line options ====
* {{MC/Cd|--help}} - Shows usage information
* {{cd|--help}} - Shows usage information
* {{MC/Cd|--packs <path>}} - Set a folder of datapacks to include in the world
* {{cd|--packs <path>}} - Set a folder of datapacks to include in the world
** Any zip file or folder with a {{MC/Cd|pack.mcmeta}} file is included
** Any zip file or folder with a {{cd|pack.mcmeta}} file is included
* {{MC/Cd|--report <path>}} - Exports results in a [https://junit.org/ junit]-like XML report at the given path
* {{cd|--report <path>}} - Exports results in a [https://junit.org/ junit]-like XML report at the given path
* {{MC/Cd|--tests <selection>}} - Specify which tests to run with a selection - a wildcard expression matching namespace test instance IDs
* {{cd|--tests <selection>}} - Specify which tests to run with a selection - a wildcard expression matching namespace test instance IDs
** If omitted, or used with an empty ID, runs all tests
** If omitted, or used with an empty ID, runs all tests
* {{MC/Cd|--universe <path>}} - The path to where the test server world will be created
* {{cd|--universe <path>}} - The path to where the test server world will be created
** Any existing folder will be replaced
** Any existing folder will be replaced
** Default: {{MC/Cd|gametestserver}}
** Default: {{cd|gametestserver}}
* {{MC/Cd|--verify <boolean>}} - Enables test verification
* {{cd|--verify <boolean>}} - Enables test verification
** Runs the tests specified with {{MC/Cd|test}} or {{MC/Cd|testNamespace}} 100 times for each 90 degree rotation step
** Runs the tests specified with {{cd|test}} or {{cd|testNamespace}} 100 times for each 90 degree rotation step
** Default: {{MC/Cd|false}}
** Default: {{cd|false}}


==== Exit code ====
==== Exit code ====
The game will yield the following {{MC/Wikipedia|exit code|exit codes}} depending on the scenario:
The game will yield the following {{wikipedia|exit code|exit codes}} depending on the scenario:


{| class="wikitable"
{| class="wikitable"
Line 83: Line 83:


== ''Bedrock Edition'' ==
== ''Bedrock Edition'' ==
The GameTest framework can be accessed through the <code>@minecraft/server-gametest</code> module from the Script API. The module must be added as a dependency in the [[Minecraft:manifest.json]]. It contains many {{MC/W|programming interface}}s used for {{MC/W|automated testing}} of any game objects' behaviors and interactions in a controlled testing environment.<ref>{{cite |url=https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-gametest/test?view=minecraft-bedrock-experimental |title=Test Class |website=Microsoft Learn |date=February 10, 2025}}</ref> Developers can use these interfaces for:
The GameTest framework can be accessed through the <code>@minecraft/server-gametest</code> module from the [[Minecraft:Script API]]. The module must be added as a dependency in the [[Minecraft:manifest.json]]. It contains many {{w|programming interface}}s used for {{w|automated testing}} of any game objects' behaviors and interactions in a controlled testing environment.<ref>{{cite |url=https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-gametest/test?view=minecraft-bedrock-experimental |title=Test Class |website=Microsoft Learn |date=February 10, 2025}}</ref> Developers can use these interfaces for:
* Asserting certain conditions for [[Minecraft:block]]s, entities, and other game objects;
* Asserting certain conditions for [[Minecraft:block]]s, [[Minecraft:entities]], and other game objects;
* Getting in-game information such as [[Minecraft:dimension]], position, entities and blocks information;
* Getting in-game information such as [[Minecraft:dimension]], [[Minecraft:position]], entities and blocks information;
* Modifying the testing environment by setting block permutation (block type and states data), sending [[Minecraft:redstone]] interactions, etc;
* Modifying the testing environment by setting block permutation (block type and states data), sending [[Minecraft:redstone]] interactions, etc;
* Spawning entities controlled by the script with predictable mob behaviors;
* Spawning entities controlled by the script with predictable mob behaviors;
* Creating simulated players for testing behaviors and interactions with other game objects;<ref>{{cite |url=https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-gametest/simulatedplayer?view=minecraft-bedrock-experimental |title=SimulatedPlayer Class |website=Microsoft Learn |date=February 10, 2025}}</ref>
* Creating simulated [[Minecraft:player]]s for testing behaviors and interactions with other game objects;<ref>{{cite |url=https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-gametest/simulatedplayer?view=minecraft-bedrock-experimental |title=SimulatedPlayer Class |website=Microsoft Learn |date=February 10, 2025}}</ref>
* And other testing functionalities, [https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-gametest/test?view=minecraft-bedrock-experimental further reading].
* And other testing functionalities, [https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-gametest/test?view=minecraft-bedrock-experimental further reading].


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.<ref>{{cite |url=https://learn.microsoft.com/en-us/minecraft/creator/documents/gametestbuildyourfirstgametest?view=minecraft-bedrock-stable |title=Building your first GameTest |website=Microsoft Learn |date=June 20, 2024}}</ref><ref name="registration-builder"/> Users can register a new unit test using <code>GameTest#register(''testClassName'', ''testName'', ''testFunction'')</code> method with additional builder parameters, such as <code>.maxTicks(''ticks'')</code> that indicates the test may take amount of ''ticks'' to run, <code>.maxAttempts(''attempts'')</code> which specifies how many attempt the test can run, and more.<ref name="registration-builder">{{cite |url=https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-gametest/registrationbuilder?view=minecraft-bedrock-experimental |title=RegistrationBuilder Class |website=Microsoft Learn |date=February 22, 2025}}</ref>
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 [[Minecraft:.mcstructure]] file exists in the behavior pack.<ref>{{cite |url=https://learn.microsoft.com/en-us/minecraft/creator/documents/gametestbuildyourfirstgametest?view=minecraft-bedrock-stable |title=Building your first GameTest |website=Microsoft Learn |date=June 20, 2024}}</ref><ref name="registration-builder"/> Users can register a new unit test using <code>GameTest#register(''testClassName'', ''testName'', ''testFunction'')</code> method with additional [[Minecraft:w:Builder pattern|builder]] parameters, such as <code>.maxTicks(''ticks'')</code> that indicates the test may take amount of ''ticks'' to run, <code>.maxAttempts(''attempts'')</code> which specifies how many attempt the test can run, and more.<ref name="registration-builder">{{cite |url=https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-gametest/registrationbuilder?view=minecraft-bedrock-experimental |title=RegistrationBuilder Class |website=Microsoft Learn |date=February 22, 2025}}</ref>


After the unit test is registered, it is loaded in the world, and can be run using the {{MC/Cmd|gametest}} command, referenced by <code>''<testClassName>'':''<testName>''</code>. 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.
After the unit test is registered, it is loaded in the world, and can be run using the {{cmd|gametest}} command, referenced by <code>''<testClassName>'':''<testName>''</code>. 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.


== History ==
== History ==
=== Demonstration ===
=== Demonstration ===
{{HistoryTable
{{HistoryTable
|{{MC/HistoryLine||November 9, 2020|link=https://www.youtube.com/watch?v=vXaWOJTCYNg|Henrik Kniberg demonstrated GameTest, a test framework used internally by Mojang, on the ''Agile with Jimmy'' YouTube channel.}}
|{{HistoryLine||November 9, 2020|link=https://www.youtube.com/watch?v=vXaWOJTCYNg|[[Minecraft:Henrik Kniberg]] demonstrated GameTest, a test framework used internally by Mojang, on the ''Agile with Jimmy'' YouTube channel.}}
}}
}}


=== ''Java Edition'' ===
=== ''Java Edition'' ===
{{HistoryTable
{{HistoryTable
|{{MC/HistoryLine|java}}
|{{HistoryLine|java}}
|{{MC/HistoryLine||1.15|dev=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.}}
|{{HistoryLine||1.15|dev=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.}}
|{{MC/HistoryLine||1.17|dev=21w13a|GameTest related code is now exposed for mod developers' use because unused parts of code are no longer removed.}}
|{{HistoryLine||1.17|dev=21w13a|GameTest related code is now exposed for mod developers' use because unused parts of code are no longer removed.}}
|{{MC/HistoryLine||1.21.5|dev=25w03a|Overhauled the GameTest framework.|Introduced for use with data packs.}}
|{{HistoryLine||1.21.5|dev=25w03a|Overhauled the GameTest framework.|Introduced for use with data packs.}}
|{{HistoryLine||1.21.11|dev=25w44a|In the {{MC/Cd|game_rules}} test environment the keys {{MC/Cd|bool_rule}} and {{MC/Cd|int_rule}} have been replaced with a single key rules.}}
|{{HistoryLine||1.21.11|dev=25w44a|In the {{cd|game_rules}} test environment the keys {{cd|bool_rule}} and {{cd|int_rule}} have been replaced with a single key rules.}}
|{{HistoryLine||26.1|dev=snap3|Replaced {{MC/Cd|time_of_day}} with {{MC/Cd|clock_time}}.|Added a new required field {{MC/Cd|clock}}: world clock ID, the clock within which to set time (from the existing time field).}}
|{{HistoryLine||26.1|dev=snap3|Replaced {{cd|time_of_day}} with {{cd|clock_time}}.|Added a new required field {{cd|clock}}: world clock ID, the clock within which to set time (from the existing time field).}}
|{{HistoryLine|||dev=snap11|Added {{MC/Cd|timeline_attributes}} definitions to set any number of timelines.}}
|{{HistoryLine|||dev=snap11|Added {{cd|timeline_attributes}} definitions to set any number of timelines.}}
}}
}}


=== ''Bedrock Edition'' ===
=== ''Bedrock Edition'' ===
{{HistoryTable
{{HistoryTable
|{{MC/HistoryLine|bedrock}}
|{{HistoryLine|bedrock}}
|{{MC/HistoryLine||1.16.210|dev=beta 1.16.210.60|Added GameTest framework.}}
|{{HistoryLine||1.16.210|dev=beta 1.16.210.60|Added GameTest framework.}}
}}
}}


== References ==
== References ==
{{MC/Reflist}}
{{reflist}}


== Navigation ==
== Navigation ==
{{MC/Navbox Java Edition technical|general}}
{{Navbox Java Edition technical|general}}
{{MC/Navbox Bedrock Edition}}
{{Navbox Bedrock Edition}}


de:Spieltest
[[Minecraft:de:Spieltest]]
ja:ゲームテスト
[[Minecraft:ja:ゲームテスト]]
pt:GameTest
[[Minecraft:pt:GameTest]]
ru:Игровой тест
[[Minecraft:ru:Игровой тест]]
zh:游戏测试
[[Minecraft:zh:游戏测试]]

Revision as of 11:09, 15 April 2026

Template:Redirect Template:Redirect GameTest is an automated Template:Wikipedia framework for Template:Wikipedia aspects of Minecraft:Minecraft. Each test contains a structure, parameters for how the test gets executed, and optional code to further specify the test behavior.

Java Edition

Test instance

File:Test instance block UI.png
UI of test instance block

Test instance can be defined in a datapack by creating a Minecraft:JSON file in the Template:Cd registry. Players can inspect information about them using a Template:BlockLink. A test instance has the following properties:

  • It belongs to a test environment, which groups the test and further specifies the environment in which the test is run in. (Template:NbtTemplate:Nbt)
  • It is associated with a Template:Nbt, which should contain all the blocks and entities it needs to be run. The structure can be easily altered with the test instance block.
  • It can either be a block-based test or a function test. More information is available below.

There are more configuration available for test instances. For more information on the format, see Minecraft:test instance definition.

Block-based

In block-based tests, Minecraft:Test blocks are used inside the test structure to control the test logic using Minecraft:redstone signal.

If a race condition occurs, the first test block activated always wins.

Function

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 Minecraft:mod developers.

The game provides the GameTest framework interfaces through the net.minecraft.gametest.framework package (Mojang mapping). Minecraft:Mod loaders typically to 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 Template:Nbt field in the test instance definition should contain the Minecraft:resource location of the test function.

Test environment

Template:Main

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 Minecraft:JSON file in the Template:Cd registry or directly specified the environment inline with the Template:Nbt field. It can also use the test environment of the vanilla data package Template:Cd, which is empty preconditions.

Test command

Template:Main The Template:Cmd 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.

Server.jar entry point

The net.minecraft.gametest.Main entry point is included in Minecraft:server.jar which starts a server, runs all available game tests and then exits. It can be invoked in the command line, such as:

<syntaxhighlight lang="bash"> java -DbundlerMainClass="net.minecraft.gametest.Main" -jar server.jar [<options>] </syntaxhighlight>

Command-line options

  • Template:Cd - Shows usage information
  • Template:Cd - Set a folder of datapacks to include in the world
    • Any zip file or folder with a Template:Cd file is included
  • Template:Cd - Exports results in a junit-like XML report at the given path
  • Template:Cd - Specify which tests to run with a selection - a wildcard expression matching namespace test instance IDs
    • If omitted, or used with an empty ID, runs all tests
  • Template:Cd - The path to where the test server world will be created
    • Any existing folder will be replaced
    • Default: Template:Cd
  • Template:Cd - Enables test verification

Exit code

The game will yield the following Template:Wikipedia 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

Bedrock Edition

The GameTest framework can be accessed through the @minecraft/server-gametest module from the Minecraft:Script API. The module must be added as a dependency in the Minecraft:manifest.json. It contains many Template:Ws used for Template:W of any game objects' behaviors and interactions in a controlled testing environment.<ref>Template:Cite</ref> 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 Minecraft:.mcstructure file exists in the behavior pack.<ref>Template:Cite</ref><ref name="registration-builder"/> 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.<ref name="registration-builder">Template:Cite</ref>

After the unit test is registered, it is loaded in the world, and can be run using the Template:Cmd 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.

History

Demonstration

Template:HistoryTable

Java Edition

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

References

Template:Reflist

Navigation

Template:Navbox Java Edition technical Template:Navbox Bedrock Edition

Minecraft:de:Spieltest Minecraft:ja:ゲームテスト Minecraft:pt:GameTest Minecraft:ru:Игровой тест Minecraft:zh:游戏测试