Skip to main content
HRTK injects context objects into test methods based on their parameter types. Each context interface provides methods relevant to a specific testing domain. This page is the complete method reference.

TestContext

The base context available to all tests. Provides logging, event capture, and command execution.
MethodReturnsDescription
getPluginName()StringName of the plugin whose tests are running
log(message)voidLog a message to test output
log(format, args...)voidLog a formatted message (printf-style)
captureEvent(eventType)EventCapture<E>Start capturing events of the given type
createCommandSender()MockCommandSenderCreate a mock sender with no permissions
createCommandSender(perms...)MockCommandSenderCreate a mock sender with specific permissions
createMockPlayer()MockPlayerRefCreate a mock player entity for testing player-related logic
executeCommand(cmd, sender)voidExecute a command as the given sender

EcsTestContext

Extends TestContext. Provides direct ECS store access, entity creation, component operations, tick-waiting, and entity queries. Available when using @EcsTest.
CategoryMethodReturnsDescription
StoregetStore()ObjectThe ECS store (runtime: Store<EntityStore>)
getCommandBuffer()ObjectCommand buffer for deferred operations
EntitycreateEntity()ObjectCreate an empty entity, returns reference
flush()voidExecute deferred command buffer operations
ComponentsputComponent(ref, type, comp)voidAttach a component to an entity
removeComponent(ref, type)voidRemove a component from an entity
getComponent(ref, type)ObjectGet component (null if absent)
hasComponent(ref, type)booleanCheck if entity has component
TickswaitTicks(n)voidBlock until N ticks elapse
waitTicksAsync(n)FutureNon-blocking tick wait
awaitCondition(fn, max)TPoll until non-null or timeout
awaitCondition(fn, max, msg)TPoll with custom failure message
QueriesfindEntities(type)List<?>Find entities with component type
countEntities(type)intCount entities with component type

WorldTestContext

Extends TestContext. Provides full world access including blocks, entity spawning, positioning, and all ECS operations. Available when using @WorldTest, @CombatTest, @SpawnTest, or @FlowTest.
CategoryMethodReturnsDescription
WorldgetWorld()ObjectThe Hytale World object
StoregetStore()ObjectEntity store for the world
getCommandBuffer()ObjectCommand buffer for deferred operations
flush()voidExecute deferred operations
BlockssetBlock(x,y,z, type)voidPlace a block
getBlock(x,y,z)StringGet block type ID
fillRegion(...)voidFill a region with blocks
SpawnspawnEntity(type)ObjectSpawn at origin - tries NPCPlugin first, falls back to empty entity if role not found
spawnEntity(type, x,y,z)ObjectSpawn at position - tries NPCPlugin first, falls back to empty entity if role not found
spawnNPC(role, x,y,z)ObjectSpawn a fully initialized NPC - throws if role not found
spawnNPC(role, variant, x,y,z)ObjectSpawn NPC with a specific variant - throws if role not found
EntityputComponent(ref, type, comp)voidAttach component
removeComponent(ref, type)voidRemove component
entityExists(ref)booleanCheck if reference is valid
despawn(ref)voidRemove entity from world
PositiongetPosition(ref)double[]Get [x, y, z]
setPosition(ref, x,y,z)voidSet position
TickswaitTicks(n)voidBlock for N ticks
waitTicksAsync(n)FutureNon-blocking wait
awaitCondition(fn, max)TPoll until non-null
awaitCondition(fn, max, msg)TPoll with message
QueriesfindEntities(type)List<?>Find by component
countEntities(type)intCount by component
getComponent(ref, type)ObjectGet component
hasComponent(ref, type)booleanCheck component
ThreadexecuteOnWorld(Supplier)TRuns code on the world thread and returns the result. Use this when calling mod APIs that access the Store.
runOnWorld(Runnable)voidSame as executeOnWorld but without a return value.
executeOnWorld() exists because mod APIs often access the ECS Store internally, which requires the world thread. When your test runs on a different thread (like @FlowTest), wrap mod API calls in executeOnWorld() to avoid “Assert not in thread” errors.

BenchmarkContext

Extends TestContext. Provides iteration info and manual timing control. Available when using @Benchmark.
MethodReturnsDescription
getIteration()intCurrent iteration number (0-based)
getTotalIterations()intTotal measured iterations
isWarmup()booleanTrue during warmup phase
startTimer()voidManually start timing measurement
stopTimer()voidStop timing measurement

Parameter Injection

HRTK’s TestExecutor resolves method parameters by type:
Parameter TypeResolved To
TestContextThe base context
EcsTestContextECS context (if available)
WorldTestContextWorld context (if available)
BenchmarkContextBenchmark context (if benchmarking)
MockCommandSenderA new mock sender with no permissions
WorldThe Hytale World object (if world context)
StoreThe ECS store (if world or ECS context)
CommandBufferA command buffer (if world or ECS context)
If a requested context type is not available (e.g., requesting WorldTestContext in a non-world test), the parameter is injected as null. Design your tests to request only the context they need.

Next Steps