Skip to main content
World tests operate on a Hytale world instance, letting you spawn entities, place blocks, move objects, and verify world state. The WorldTestContext provides direct access to the world, its ECS store, block operations, and tick-waiting primitives. World testing is where ECS meets the game world. While ECS tests work with raw entities and components, world tests verify that entities spawn at the right coordinates, blocks are placed correctly, and the world ticks forward as expected.
Entity type names and block IDs used in examples (like Kweebec, Soil_Dirt) are from Hytale’s default content. Replace them with your mod’s actual entity roles and block type IDs. The spawnEntity method tries NPCPlugin first and falls back to an empty entity if the role is not found. Block IDs use the asset name without a namespace prefix.

Isolation Strategies for World Tests

World tests modify shared state - blocks, entities, positions. Without isolation, your tests could corrupt the live server or interfere with each other. HRTK provides two strategies:
  • DEDICATED_WORLD - Each suite gets a temporary void world that is destroyed after the suite. This is the recommended default for any test that places blocks or spawns entities.
  • SNAPSHOT - The world state is captured before the suite and restored after. Useful when you need to test against existing world content.

Complete Example Suite

WorldTestContext Methods

WorldAssert Methods

Entity Spawning: spawnEntity vs spawnNPC

When you call spawnEntity(typeId) or spawnEntity(typeId, x, y, z), HRTK first attempts to spawn a fully typed entity using NPCPlugin.spawnNPC(). This produces an entity with all the components and behaviors defined for that NPC type (health, AI, model, etc.). If the NPCPlugin call fails or the type is not recognized, HRTK falls back to creating an empty entity with no components attached. When you call spawnNPC(role, x, y, z), HRTK directly invokes NPCPlugin.spawnNPC() with the role name. This always produces a fully initialized NPC or fails explicitly - there is no fallback to an empty entity.
For tests that need a fully initialized entity (with health, AI, and other NPC components), prefer spawnNPC("Kweebec_Sapling", ...) over spawnEntity(...). The NPC path is more explicit and gives clearer error messages when spawning fails.

fillRegion Performance

fillRegion() batches all block placements into a single world-thread dispatch. This means the entire region is filled atomically within one tick, rather than issuing separate block placements per coordinate. This makes large fills significantly faster and ensures the region is consistent when you assert against it.

Next Steps