Skip to content

Commit db62d21

Browse files
committed
chore: add gametests
1 parent 7e1b297 commit db62d21

File tree

6 files changed

+444
-0
lines changed

6 files changed

+444
-0
lines changed

build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,30 @@ loom {
2727
sourceSet sourceSets.client
2828
}
2929
}
30+
}
31+
32+
33+
fabricApi {
34+
configureTests {
35+
createSourceSet = true
36+
enableGameTests = true
37+
enableClientGameTests = false
38+
modId = "scl_tests"
39+
eula = true
40+
}
41+
}
42+
43+
// `loom/runs` has to appear after the `fabricApi` block since it depends on
44+
// `sourceSets.gametest`, but `loom/splitEnvironmentSourceSets()` must be before.
45+
loom {
46+
runs {
47+
gameTestClient {
48+
inherit client
3049

50+
configName = "GameTest Minecraft Client"
51+
source = sourceSets.gametest
52+
}
53+
}
3154
}
3255

3356
dependencies {

docs/testing.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)