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.
public interface TestContext {
    String getPluginName();
    void log(String message);
    void log(String format, Object... args);
    <E> EventCapture<E> captureEvent(Class<E> eventType);
    MockCommandSender createCommandSender();
    MockCommandSender createCommandSender(String... permissions);
    void executeCommand(String commandLine, MockCommandSender sender);
}
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
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.
public interface EcsTestContext extends TestContext {
    Object getStore();
    Object getCommandBuffer();
    Object createEntity();
    void flush();
    void putComponent(Object ref, Object type, Object component);
    void removeComponent(Object ref, Object type);
    Object getComponent(Object ref, Object type);
    boolean hasComponent(Object ref, Object type);
    void waitTicks(int ticks);
    CompletableFuture<Void> waitTicksAsync(int ticks);
    <T> T awaitCondition(Supplier<T> condition, int maxTicks);
    <T> T awaitCondition(Supplier<T> condition, int maxTicks, String failMessage);
    List<?> findEntities(Object componentType);
    int countEntities(Object componentType);
}
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.
public interface WorldTestContext extends TestContext {
    Object getWorld();
    Object getStore();
    Object getCommandBuffer();
    void flush();
    void setBlock(int x, int y, int z, String typeId);
    String getBlock(int x, int y, int z);
    void fillRegion(int x1, int y1, int z1, int x2, int y2, int z2, String typeId);
    Object spawnEntity(String typeId);
    Object spawnEntity(String typeId, double x, double y, double z);
    void putComponent(Object ref, Object type, Object comp);
    void removeComponent(Object ref, Object type);
    boolean entityExists(Object ref);
    void despawn(Object ref);
    void waitTicks(int ticks);
    CompletableFuture<Void> waitTicksAsync(int ticks);
    <T> T awaitCondition(Supplier<T> condition, int maxTicks);
    <T> T awaitCondition(Supplier<T> condition, int maxTicks, String failMessage);
    List<?> findEntities(Object componentType);
    int countEntities(Object componentType);
    Object getComponent(Object ref, Object type);
    boolean hasComponent(Object ref, Object type);
    double[] getPosition(Object ref);
    void setPosition(Object ref, double x, double y, double z);
}
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
spawnEntity(type, x,y,z)ObjectSpawn at position
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

BenchmarkContext

Extends TestContext. Provides iteration info and manual timing control. Available when using @Benchmark.
public interface BenchmarkContext extends TestContext {
    int getIteration();
    int getTotalIterations();
    boolean isWarmup();
    void startTimer();
    void stopTimer();
}
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