@minecraft/server-gametest Module

Important

These APIs are experimental as part of the Beta APIs experiment. As with all experiments, you may see changes in functionality in updated Minecraft versions. Check the Minecraft Changelog for details on any changes to Beta APIs. Where possible, this documentation reflects the latest updates to APIs in Minecraft beta versions. The @minecraft/server-gametest module provides scriptable APIs for scaffolding and testing content experiences in Minecraft.

Caution

This module is still in pre-release. It may change or it may be removed in future releases.

Manifest Details

{
    "module_name": "@minecraft/server-gametest",
    "version": "1.0.0-beta"
}

Available Versions

  • 1.0.0-beta

Classes

Functions

register

static register(testClassName: string, testName: string, testFunction: (arg: Test) => void): RegistrationBuilder

Registers a new GameTest function. This GameTest will become available in Minecraft via /gametest run [testClassName]:[testName].

Parameters

  • testClassName: string

    Name of the class of tests this test should be a part of.

  • testName: string

    Name of this specific test.

  • testFunction: (arg: Test) => void

    Implementation of the test function.

Returns RegistrationBuilder - Returns a @minecraft/server-gametest.RegistrationBuilder object where additional options for this test can be specified via builder methods.

Examples

example1.js
GameTest.register("ExampleTests", "alwaysFail", (test) => {
  test.fail("This test, runnable via '/gametest run ExampleTests:alwaysFail', will always fail");
});
simpleMobTest.ts
  gt.register("StarterTests", "simpleMobTest", (test: gt.Test) => {
    const attackerId = "fox";
    const victimId = "chicken";
    test.spawn(attackerId, new mc.BlockLocation(5, 2, 5));
    test.spawn(victimId, new mc.BlockLocation(2, 2, 2));
    test.assertEntityPresentInArea(victimId, true);
    test.succeedWhen(() => {
      test.assertEntityPresentInArea(victimId, false);
    });
  })
    .maxTicks(400)
    .structureName("gametests:mediumglass");

registerAsync

static registerAsync(testClassName: string, testName: string, testFunction: (arg: Test) => Promise<void>): RegistrationBuilder

Registers a new GameTest function that is designed for asynchronous execution. This GameTest will become available in Minecraft via /gametest run [testClassName]:[testName].

Parameters

  • testClassName: string

    Name of the class of tests this test should be a part of.

  • testName: string

    Name of this specific test.

  • testFunction: (arg: Test) => Promise<void>

    Implementation of the test function.

Returns RegistrationBuilder - Returns a @minecraft/server-gametest.RegistrationBuilder object where additional options for this test can be specified via builder methods.

Change Log

1.0.0-beta

Added @minecraft/server-gametest Module