Edit

Share via


@minecraft/server-gametest Module

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.

Changelog

Manifest Details

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

This is version 1.x.x of this module, which is the latest as of version 1.21.100-beta.23 of Minecraft.

Available Versions

  • 1.0.0-beta

Enumerations

Classes

Interfaces

Errors

Functions

register

register(testClassName: string, testName: string, testFunction: (arg0: 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: (arg0: 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.

Notes:

  • This function can't be called in read-only mode.
  • This function can be called in early-execution mode.

Examples

simpleMobGameTest.ts
import { Test, register } from "@minecraft/server-gametest";
import { MinecraftEntityTypes } from "@minecraft/vanilla-data";

function simpleMobGameTest(test: Test) {
  const attackerId = MinecraftEntityTypes.Fox;
  const victimId = MinecraftEntityTypes.Chicken;

  test.spawn(attackerId, { x: 5, y: 2, z: 5 });
  test.spawn(victimId, { x: 2, y: 2, z: 2 });

  test.assertEntityPresentInArea(victimId, true);

  test.succeedWhen(() => {
    test.assertEntityPresentInArea(victimId, false);
  });
}
register("StarterTests", "simpleMobTest", simpleMobGameTest).maxTicks(400).structureName("gametests:mediumglass");

(preview) Work with this sample on the MCTools.dev code sandbox.

registerAsync

registerAsync(testClassName: string, testName: string, testFunction: (arg0: 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: (arg0: 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.

Notes:

  • This function can't be called in read-only mode.
  • This function can be called in early-execution mode.

Examples

simpleMobAsyncTest.ts
import * as gameTest from '@minecraft/server-gametest';

gameTest
    .registerAsync('StarterTests', 'simpleMobTest', async (test: gameTest.Test) => {
        const attackerId = 'fox';
        const victimId = 'chicken';

        test.spawn(attackerId, { x: 5, y: 2, z: 5 });
        test.spawn(victimId, { x: 2, y: 2, z: 2 });

        test.assertEntityPresentInArea(victimId, true);

        test.succeedWhen(() => {
            test.assertEntityPresentInArea(victimId, false);
        });
    })
    .maxTicks(400)
    .structureName('gametests:mediumglass');

(preview) Work with this sample on the MCTools.dev code sandbox.

Dependencies