Skip to content

Testing

GameTestFunctions lets a mod write its GameTests once, in common code, and run them on every loader. Each loader still needs its own small class that hands the tests to its GameTest framework.

Type Summary Status Since Side Thread
GameTestFunctions Builds GameTest functions from plain classes of static @GameTest methods, the same on every loader. Experimental 2.0.0 server setup

With PathWear, the saved data from the saved data quick start:

Write a GameTest once and register it on each loader
// Common GameTest source set:
public final class WearGameTests {
@GameTest
public static void countsSteps(GameTestHelper helper) {
BlockPos pos = helper.absolutePos(new BlockPos(1, 1, 1));
PathWear wear = PathWear.get(helper.getLevel());
wear.clear(pos);
wear.step(pos);
helper.assertTrue(wear.step(pos) == 2, "two steps on one block count 2");
helper.succeed();
}
}
// Fabric (fabric-gametest entry point):
public final class MyFabricGameTests implements FabricGameTest {
@GameTestGenerator
public Collection<TestFunction> tests() { return GameTestFunctions.of(WearGameTests.class, "mymod"); }
}
// Forge:
@GameTestHolder("mymod")
public final class MyForgeGameTests {
@GameTestGenerator
public static Collection<TestFunction> tests() { return GameTestFunctions.of(WearGameTests.class, "mymod"); }
}

Experimental · Since 2.0.0 · Side: server · Thread: setup

A mod with several classes of tests returns them from one generator per loader. With WearGameTests from the quick start and ConfigGameTests, another class of @GameTest methods:

Register several classes of tests from one generator
private static final List<Class<?>> CLASSES = List.of(WearGameTests.class, ConfigGameTests.class);
@GameTestGenerator
public static Collection<TestFunction> tests() {
List<TestFunction> all = new ArrayList<>();
for (Class<?> tests : CLASSES) all.addAll(GameTestFunctions.of(tests, "mymod"));
return all;
}
  • Tests ported from Fabric’s EMPTY_STRUCTURE expect an 8 by 8 by 8 structure of air. Stope’s own empty structure is that size; make the mod’s empty structure the same size.
  • GameTestFunctions ships in Stope’s jar, so a mod’s GameTest source set compiles against it.