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.
At a glance
Section titled “At a glance”| 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 |
Quick start
Section titled “Quick start”With PathWear, the saved data from the
saved data quick start:
// 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"); }}GameTestFunctions
Section titled “GameTestFunctions”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:
private static final List<Class<?>> CLASSES = List.of(WearGameTests.class, ConfigGameTests.class);
@GameTestGeneratorpublic 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_STRUCTUREexpect an 8 by 8 by 8 structure of air. Stope’s ownemptystructure is that size; make the mod’semptystructure the same size. GameTestFunctionsships in Stope’s jar, so a mod’s GameTest source set compiles against it.
See also
Section titled “See also”- Using Stope from a mod: adding Stope to a build.
- Test behavior with GameTest: a guide that sets up and runs tests step by step.