| name | rust-testing |
| description | Patterns for Rust testing in Axone CosmWasm contracts. Use when adding unit tests, integration tests, data-driven cases, or coverage-oriented test scenarios. |
| license | BSD-3-Clause |
| metadata | {"author":"axone.xyz","version":"1.0"} |
Rust Testing
Coverage Targets
| Component | Target |
|---|
| Handlers | 100% |
| State operations | 100% |
| Error paths | 90%+ |
| Message parsing | 80%+ |
| Overall | 90%+ |
Minimum Cases to Cover
- For handlers: cover the happy path, parameter variations, error paths, and resulting state changes.
- For queries: cover empty state, populated state, pagination behavior, and non-existent items.
- For state transitions: cover initial state, updates after execute, and persistence across operations.
Running Tests
cargo make test-unit
cargo make test
cargo make test-coverage
cargo test test_name -- --nocapture
Coverage output is written to lcov.info.
Viewing Coverage
genhtml lcov.info --output-directory coverage/
cargo llvm-cov --html --open
Test Design Rules
- Isolate tests. Each test should set up its own environment.
- Test contract behavior, not framework internals.
- Assert exact errors when possible.
- Cover edge cases such as zero values, empty strings, and upper bounds.
- Prefer descriptive test names without a
test_ prefix.
- Use tuple-driven cases for simple matrices and structs only when the case shape needs named fields.
References
- For cw-orch integration harness patterns and common integration scenarios, read integration-patterns.
- For naming and data-driven test examples, read test-style.