- Write tests as `test "description" { ... }` blocks directly in source files — run them with `zig build test` or `zig test src/file.zig`.
- Use `std.testing.expectEqual(expected, actual)` and `std.testing.expectError(error.Code, expr)` for assertions with clear failure messages.
- Use `std.testing.allocator` for all allocations in tests to automatically detect leaks at the end of each test block.
- Place tests at the bottom of each source file alongside the code they test — tests as inline documentation keeps coverage close to the implementation.
- Use `try std.testing.expectEqualSlices(u8, expected, actual)` to compare slices by value rather than pointer equality.
- Use `std.testing.expectApproxEqAbs(expected, actual, tolerance)` for floating-point comparisons where exact equality is unreliable.
- Use `@import` in test blocks to pull in the module under test with the exact same name as in production code to avoid drift.