Rust Testing Infrastructure
Relevant Rust source files
crates/testkit/src/lib.rscrates/testkit/src/files.rscrates/testkit/src/testers/data/mod.rscrates/testkit/src/testers/exec/mod.rscrates/testkit/tests/orderbook_integration.rscrates/testkit/tests/large_data.rscrates/model/benches/fixed_precision_criterion.rs
Rust tests are colocated with crates for private invariants and placed under crate tests/ directories for public-boundary integration. nautilus-testkit centralizes reusable data management, fixture paths, checksum verification, and data/execution tester components.
Test layers
- Unit tests cover pure model, parser, state-machine, and calculation behavior.
- Property and table-driven tests cover ranges, precision, ordering, and codec round trips.
- Integration tests cross crate boundaries such as engine plus cache, adapter plus decoder, or event-store writer plus replay.
- Live smoke tests validate provider connectivity but should not replace deterministic fixtures.
- Benchmarks establish performance evidence separately from correctness.
Use cargo nextest for the workspace test runner where configured. Run ordinary cargo test for doctests or targets not covered by the selected nextest invocation.
Deterministic fixtures
Market-data tests should pin input bytes, schema, dataset, symbology, and expected Nautilus values. Provider API calls are unsuitable as the only oracle because data and entitlements can change. Databento DBN decoding should be tested from captured DBN fixtures before a credentialed smoke test. Interactive Brokers message mapping should use deterministic protocol fixtures and isolated paper/Gateway tests for final connectivity.
nautilus-testkit can download and cache approved datasets and verify them with SHA-256. Large fixtures should remain outside the source tree unless they are intentionally small and stable.
Failure paths
Test malformed messages, range and precision errors, reconnect/resume behavior, duplicate and out-of-order events, partial startup, recovery, and shutdown. A happy-path decode test does not prove a live adapter or replay system.
Performance tests
Criterion measures statistical microbenchmarks; IAI-style instruction measurements help isolate deterministic CPU changes. Keep benchmark inputs representative and compare the same feature/profile configuration. Treat benchmark output as evidence for the named function or flow only.