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 or -Dneoforge.gameTestServer=true). Then:
  • in game, /test run <tests> runs them by id or pattern (/test run mymod:* runs all of a mod's), and /test runfailed those that failed;
  • 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 the gameTestServer run.
A test's structure comes from a data pack (data/<ns>/structure/<path>.nbt, saved with a structure block or the test block); without one, tests run on GameTestOptions.PLATFORM.
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<net.minecraft.resources.Identifier>
    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.Identifier>
    register(String modId, Class<?> holder)
    Registers every GameTest method of a class, as <modid>:<class>/<method>.
    static void
    register(net.minecraft.resources.Identifier id, Consumer<net.minecraft.gametest.framework.GameTestHelper> test)
    Registers one test.
    static void
    register(net.minecraft.resources.Identifier id, GameTestOptions options, Consumer<net.minecraft.gametest.framework.GameTestHelper> test)
    Registers one test with its options.

    Methods inherited from class Object

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

    • register

      public static void register(net.minecraft.resources.Identifier 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.Identifier 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.Identifier> 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.Identifier> all()
      Every test registered so far.