For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server-gametest/functions/register.md.

Function: register()

register(testClassName, testName, testFunction): RegistrationBuilder

World Mutation Early Execution Beta

Parameters

testClassName

string

此测试所属的测试类名称。

testName

string

此具体测试的名称。

testFunction

(arg0) => void

测试函数的实现。

Returns

RegistrationBuilder

返回一个 RegistrationBuilder 对象, 可通过其构建器方法为此测试指定 其他选项。

Remarks

注册一个新的 GameTest 函数。该 GameTest 将可通过 /gametest run [testClassName]:[testName] 在 Minecraft 中运行。

Examples

simpleMobGameTest.ts
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');