CodecAssert class lets you verify that your codecs correctly round-trip data and properly reject bad input.
Codec bugs are sneaky - a field that silently disappears when saving, a decode that produces garbage instead of an error, or a round-trip that corrupts precision. These bugs often go unnoticed until a player loads a corrupted save file. Automated codec tests catch them early.
CodecAssert Methods
| Method | Description |
|---|---|
assertRoundTrip(codec, value) | Encode then decode; assert result equals original |
assertRoundTrip(codec, value, equalityCheck) | Round-trip with custom equality predicate |
assertDecodeEquals(codec, bsonValue, expected) | Decode and assert result equals expected |
assertDecodeThrows(codec, malformedBson) | Assert decoding throws an exception |
Complete Example Suite
How It Works Internally
CodecAssert automatically finds and calls the encode() and decode() methods on your codec. It works with any codec that follows the standard Hytale pattern.
The codec parameter is typed as
Object in the API so your mod doesn’t need the server JAR at compile time. At runtime, pass a Hytale Codec<T> instance.When to Test Codecs
Codec tests are essential when:- You define custom components with serialization logic
- You modify existing component codecs
- You need regression tests for data persistence formats
- You want to verify backward compatibility after schema changes
Next Steps
- ECS Testing - test component serialization in context
- Benchmarks - measure codec performance