HRTK supports four lifecycle annotations that let you run setup and teardown code at precise points in the test execution cycle. These work the same way as their JUnit counterparts, adapted for the Hytale runtime environment.
Hook Execution Order
For a suite with two tests, the execution order is:
@BeforeAll
Runs once before the first test in the suite. Must be static (or instance - HRTK supports both, but static is conventional).
Use @BeforeAll for expensive one-time setup like loading configuration files, initializing shared fixtures, or preparing test data structures.
@AfterAll
Runs once after the last test in the suite completes. Like @BeforeAll, it can be static or instance-level.
@BeforeEach
Runs before every test method in the suite. Always an instance method (not static). Use it to reset state between tests so they remain independent.
@AfterEach
Runs after every test method, regardless of whether the test passed or failed. Use it for cleanup.
Complete Example
Here is a full lifecycle example that verifies the execution order using a counter:
Multiple Hooks
You can have multiple methods with the same lifecycle annotation. All of them will run, but the order between multiple @BeforeEach methods (for example) is not guaranteed.
Lifecycle hook failures are now handled explicitly:
@BeforeAll failure: If @BeforeAll throws an exception, all tests in the suite are marked as ERRORED. The tests are not executed because the shared setup they depend on did not complete.
@AfterEach failure: If @AfterEach throws an exception, it is reported as a separate ERRORED result in the output, in addition to the test result itself. The test’s own result (pass/fail) is preserved.
@BeforeEach and @AfterAll: These hooks log warnings on failure but do not change how individual test results are reported.
Next Steps