You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/CREATING_TESTS.MD
+53-2Lines changed: 53 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,10 @@ Now you need to set a label to the computer, so it can run the lua test script.
24
24
For example, peripheraltest as the test type. The test type is the name of the `@GameTestHolder` class. PeripheralTest.kt for this type.
25
25
`environment` would be our test name. So the label would be `peripheraltest.environment`.
26
26
27
-
The computer needs the id 0 so it can load the default startup.lua and the tests scripts from the resources folder.
27
+
The computer can either have the id 0 or 1. It depends what you want to do later.
28
+
It is possible to either run a test script on the computer which is explained in "Writing the test" and you can run
29
+
code on the computer using the kotlin game tests.
30
+
Use id 0 if you want to run a lua script on the computer and id 1 if you only want to run code using kotlin game tests.
28
31
29
32
Now to save your test, get a structure block, place it in the lower right corner of the test structure and set the mode to save.
30
33
Use the command `/give @p minecraft:structure_block` to get a structure block.
@@ -44,6 +47,10 @@ The class should be annotated with `@GameTestHolder`.
44
47
The class should have a function annotated with `@GameTest` that will be executed by the game test server later.
45
48
The function needs to have the parameter `GameTestContext` that will be used to interact with the game world.
46
49
50
+
There are two ways to test things on a computer. You can either run a lua script or run code on the computer using kotlin.
51
+
52
+
#### Lua Tests
53
+
47
54
A simple game test would look like this. You can see that the context can be used to interact with the world.
48
55
You can then use one of the helper functions to interact with the computer. For example, `thenComputerOk()` to check if the script on the computer was executed without any fails.
49
56
```kt
@@ -69,4 +76,48 @@ test.eq(false, isRaining, "It should not rain")
69
76
Last but not least, import the script to the computer. You need to do that when you're currently in the test world, and you want to write the script in your IDE.
70
77
Luckily, the test framework provides a command for that.
71
78
`/cctest import` imports the scripts from the resources folder to the world folder.
72
-
You can then find the script in the computer's folder using `ls tests/`.
79
+
You can then find the script in the computer's folder using `ls tests/`.
80
+
81
+
82
+
#### Kotlin Tests
83
+
84
+
To run tests on a computer, the computer needs to have the id 1
For more examples, you can also check how the tests from CC work [here](https://github.com/cc-tweaked/CC-Tweaked/tree/mc-1.19.2/src/testMod/kotlin/dan200/computercraft/gametest).
0 commit comments