Class GameTests

java.lang.Object
net.ixdarklord.coolcatcore.api.gametest.GameTests

public final class GameTests extends Object
Game tests from common code, the same on every loader: a test is a function given a GameTestHelper, run in a structure built for it, and it passes or fails. Register them while your mod constructs, by class (methods marked GameTest) or one by one:

 GameTests.register(MOD_ID, WandTests.class);
 GameTests.register(MyMod.id("crate/keeps_items"), GameTestOptions.DEFAULT.withMaxTicks(40), helper -> {
     helper.setBlock(1, 1, 1, MyBlocks.CRATE.get());
     ...
     helper.succeed();
 });
 
Tests are added to the game only when it's run to test (isEnabled()): in a development environment, or with -Dcoolcatlib.gametest=true (or the loader's own switch, -Dfabric-api.gametest, -Dneoforge.enableGameTest=true or -Dforge.enableGameTest=true). On NeoForge and Forge, -Dneoforge.enabledGameTestNamespaces=mymod,othermod (or forge.) keeps only those mods' tests, as it does for the loader's own. Then:
  • in game, /test run <test> runs one by its name, which on this version is its id with dots (mymod:wand_tests/zaps_a_zombie is mymod.wand_tests.zaps_a_zombie); /test runall runs them all, /test runall mymod all of a mod's (/test runall mymod.wand_tests one class's), and /test runfailed those that failed. The /test command is there in a development environment and on Fabric clients; on NeoForge and Forge it's only in a development environment, where the loader allows it;
  • a game test server runs them all and exits, failing if a required one did: on Fabric a dedicated server with -Dfabric-api.gametest, on NeoForge and Forge a development server with -Dneoforge.gameTestServer=true or -Dforge.gameTestServer=true.
A test's structure comes from a data pack (data/<ns>/structure/<path>.nbt, saved with a structure block); without one, tests run on GameTestOptions.PLATFORM. The helper's positions count from the structure's corner, (0, 0, 0) being its lowest block, as on newer versions, so a test reads the same on every version (the game's own tests on this version count from the structure block, one below, except on Forge with its fixGameTestBlockPosAsserts option).
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<net.minecraft.resources.ResourceLocation>
    all()
    Every test registered so far.
    static boolean
    Whether tests are added to the game this run (see the class description).
    static List<net.minecraft.resources.ResourceLocation>
    register(String modId, Class<?> holder)
    Registers every GameTest method of a class, as <modid>:<class>/<method>.
    static void
    register(net.minecraft.resources.ResourceLocation id, Consumer<net.minecraft.gametest.framework.GameTestHelper> test)
    Registers one test.
    static void
    register(net.minecraft.resources.ResourceLocation id, GameTestOptions options, Consumer<net.minecraft.gametest.framework.GameTestHelper> test)
    Registers one test with its options.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • register

      public static void register(net.minecraft.resources.ResourceLocation id, Consumer<net.minecraft.gametest.framework.GameTestHelper> test)
      Registers one test. Call while your mod constructs; its id's namespace must be your mod id.
    • register

      public static void register(net.minecraft.resources.ResourceLocation id, GameTestOptions options, Consumer<net.minecraft.gametest.framework.GameTestHelper> test)
      Registers one test with its options. Call while your mod constructs; its id's namespace must be your mod id.
    • register

      public static List<net.minecraft.resources.ResourceLocation> register(String modId, Class<?> holder)
      Registers every GameTest method of a class, as <modid>:<class>/<method>. Call while your mod constructs.
      Returns:
      the tests' ids
    • isEnabled

      public static boolean isEnabled()
      Whether tests are added to the game this run (see the class description).
    • all

      public static List<net.minecraft.resources.ResourceLocation> all()
      Every test registered so far.