본문으로 건너뛰기
버전: Minecraft 26.2

테스트 공간과 시간

TestArea​

게임은 테스트 구역 사이를 몇 칸만 띄웁니다. 1칸보다 넓은 범위에 블록을 놓거나 몹을 움직이는 테스트는 TestArea로 공간을 확보하세요. 그러지 않으면 이웃 테스트와 겹쳐 가끔 실패합니다.

mod.gameTests().register("ore_vein", 100, TestArea.cube(9), test -> {
test.runCommand("fill ~1 ~1 ~1 ~7 ~7 ~7 minecraft:stone");
test.assertTrue(test.runCommand("place feature ruby_mod:ruby_ore ~4 ~4 ~4") == 1, "광석 배치");
test.succeed();
});
  • TestArea.cube(size)는 정육면체, new TestArea(width, height, depth)는 직육면체 공간입니다.
  • 지정하지 않으면 TestArea.SINGLE_BLOCK(1×1×1)입니다.
  • Poly 모드 로더가 그 크기의 빈 구조물을 생성 팩에 씁니다.

시간이 걸리는 테스트​

최대 틱 수를 늘리고, runAfter로 나중에 확인합니다.

mod.gameTests().register("machine_finishes", 80, test -> {
// …기계를 놓고 재료를 넣음…
test.runAfter(45, () -> {
test.assertTrue(output.count() == 1, "40틱 뒤 결과물 1개");
test.succeed();
});
});

조건이 될 때까지 기다리기​

정확한 틱 수를 모를 때는 짧은 간격으로 조건을 거듭 확인합니다. 시간 안에 조건이 충족되지 않으면 테스트는 시간 초과로 실패합니다.

/** condition을 5틱마다 확인하고, 참이 되면 then을 실행합니다. */
static void poll(GameTestContext test, BooleanSupplier condition, Runnable then) {
test.runAfter(5, () -> {
if (condition.getAsBoolean()) {
then.run();
} else {
poll(test, condition, then);
}
});
}

예약 작업 테스트​

mod.gameTests().register("scheduled_task_runs", 20, test -> {
AtomicInteger runs = new AtomicInteger();
test.world().schedule(3, runs::incrementAndGet);
test.runAfter(1, () -> test.assertTrue(runs.get() == 0, "task did not run early"));
test.runAfter(6, () -> {
test.assertTrue(runs.get() == 1, "task ran once, ran " + runs.get());
test.succeed();
});
});
게임 테스트 서버의 제약

게임 테스트 서버는 평지 프리셋으로만 차원을 만들기 때문에 데이터 차원이 없습니다. 모드 차원은 일반 월드에서 확인하세요.

Buy me a coffee