Some tests need explicit time limits (to catch hangs or slow operations), while others need to run multiple times to verify consistency. HRTK provides @Timeout and @RepeatedTest for these scenarios.
@Timeout
Every test has a default timeout of 30 seconds. If your test completes within that window, you never need to think about timeouts. But if you need a tighter or looser limit, use @Timeout.
What happens on timeout
When a test exceeds its timeout, the runner reports it as TIMED_OUT:
Timeouts on world-bound tests (@WorldTest, @EcsTest) are especially important. Because these tests run on the world thread, a stuck test would stall the entire world’s tick loop. The timeout ensures the runner gives up and moves on, preserving server stability.
Supported time units
The unit parameter accepts any java.util.concurrent.TimeUnit value:
| Unit | Example |
|---|
TimeUnit.MILLISECONDS | @Timeout(value = 200, unit = TimeUnit.MILLISECONDS) |
TimeUnit.SECONDS | @Timeout(5) (default unit) |
TimeUnit.MINUTES | @Timeout(value = 2, unit = TimeUnit.MINUTES) |
@RepeatedTest
Run the same test method multiple times. Each repetition is reported as a separate result. This is useful for detecting flaky behavior, race conditions, or probabilistic logic.
Output
Each repetition appears as its own result:
@RepeatedTest implies @HytaleTest - you do not need both annotations. The value parameter specifies the number of repetitions.
@RepeatedTest(0) is invalid and will be reported as ERRORED at discovery time. The repetition count must be at least 1. Similarly, @ParameterizedTest without a @ValueSource annotation will be reported as ERRORED rather than silently skipped.
Combining with @BeforeEach / @AfterEach
Lifecycle hooks run for every repetition, so each iteration gets a clean setup:
Combining with —fail-fast
When --fail-fast is enabled and a repeated test fails on any iteration, the remaining repetitions are skipped:
Combining @Timeout and @RepeatedTest
You can use both annotations together. The timeout applies to each individual repetition.
Use @RepeatedTest with a tight @Timeout to stress-test performance-sensitive code paths. If any of the repetitions times out, you know your code has worst-case latency issues.
Next Steps