|
| 1 | +# Testing |
| 2 | + |
| 3 | +This project uses the [Minecraft GameTest framework](https://minecraft.wiki/w/GameTest) |
| 4 | +along with [Fabric's GameTest integration](https://docs.fabricmc.net/develop/automatic-testing#writing-game-tests) |
| 5 | +for testing. |
| 6 | + |
| 7 | +File structure |
| 8 | +``` |
| 9 | +src/ |
| 10 | + gametest/ # Module for all things GameTest. |
| 11 | + java/ |
| 12 | + io.nihlen.scriptschunkloaders/ # Package in which we put our tests. |
| 13 | + ScriptsChunkLoadersGameTest.java # We can have multiple test files. Also add to fabric.mod.json. |
| 14 | + resources/ |
| 15 | + data.scl_tests/ |
| 16 | + structure/ # Structures referenced by the tests live here. |
| 17 | + basic.nbt |
| 18 | + empty.nbt |
| 19 | + fabric.mod.json # The GameTests are in their own mod which is defined here. |
| 20 | + main/ # The ordinary mod files. |
| 21 | +``` |
| 22 | + |
| 23 | +You can launch Minecraft with the GameTest mod loaded by running the "GameTest |
| 24 | +Minecraft Client" configuration. |
| 25 | + |
| 26 | +To design a new structure for a test, make sure to first define the structure in |
| 27 | +your test code: |
| 28 | +```java |
| 29 | +@GameTest(structure = "scl_tests:my_new_structure") |
| 30 | +public void my_new_test(TestContext context) { |
| 31 | + // Your test goes here |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +Then start the game. Open a world and run the command |
| 36 | +`/test create scl_tests:scripts_chunk_loaders_game_test_my_new_test` |
| 37 | +(autocomplete will help you). |
| 38 | + |
| 39 | +A test area will be generated in which your can design your test. To save the |
| 40 | +structure, right click the Test Block and click "Save Structure". Your structure |
| 41 | +will be saved in |
| 42 | +`run/saves/<your_save>/generated/scl_tests/structures/my_new_structure.nbt`. |
| 43 | +Move this into `src/gametest/resources/data/scl_tests/structure` to ensure it's |
| 44 | +commited into Git. |
| 45 | + |
| 46 | +## Hotswapping tests |
| 47 | + |
| 48 | +To hotswap tests, make sure to have your IDE configured to use the JetBrains |
| 49 | +Runtime and add `-XX:+AllowEnhancedClassRedefinition` to your VM Arguments for |
| 50 | +the "GameTest Minecraft Client" configuration. You can then start the game using |
| 51 | +the debugger and enjoy hotswapping of existing tests. |
| 52 | + |
| 53 | +You can read more about hotswapping in the [Fabric documentation](https://docs.fabricmc.net/develop/getting-started/launching-the-game#hotswapping-classes). |
| 54 | + |
| 55 | + |
0 commit comments