IsolationStrategy.SNAPSHOT tracks entities created during your suite and removes them when the suite finishes. This is not a full state snapshot - it only records which entities were created so they can be cleaned up. Existing entities are not captured or restored.
When to Use
- Tests that create entities and need them cleaned up automatically
- Tests that attach components to newly created entities
- Any test where you want created entities removed after the suite
How It Works
Before Suite
HRTK creates a
TestEntityTracker that begins recording entity creations in the ECS store.Test Execution
Your tests run normally, creating entities and mutating ECS state as needed. The tracker records every entity created during the suite.
Usage
What Is Tracked and What Is Not
| Tracked (cleaned up) | Not Tracked (persists) |
|---|---|
| Entities created during the suite | Modifications to pre-existing entities |
| Components attached to tracked entities | Block state (placed/broken blocks) |
| Stat changes on pre-existing entities | |
| World-level configuration | |
| File system changes | |
| Event listener registrations |
Performance
Entity tracking has minimal overhead - it simply records references to created entities during the suite and removes them at the end. The cleanup cost scales with the number of entities created, not the total size of the ECS store. This cost is paid once per suite (not per test).Complete Example
Next Steps
- Isolation: NONE - no protection, fastest
- Isolation: DEDICATED_WORLD - full world isolation
- Isolation Overview - strategy comparison