Coverage
Test coverage measures how much of your code is exercised by tests. The Aptos CLI supports generating coverage reports for your Move packages.
Generating Coverage
Run tests with coverage enabled:
aptos move test --dev --coverage
This runs your tests and generates a coverage report.
Viewing Coverage
After running tests with coverage, view the summary:
aptos move coverage summary --dev
This shows the percentage of code covered by tests for each module.
For a detailed source-level report:
aptos move coverage source --module counter --dev
This shows which lines of code were covered (marked) and which were not.
Interpreting Coverage
- High coverage (>80%) indicates that most code paths are tested.
- Low coverage means there are untested code paths that could contain bugs.
- 100% coverage does not guarantee correctness -- it only means every line was executed.
Focus on testing:
- All public entry points
- All error conditions
- Edge cases and boundary values
- State transitions
Best Practices
- Aim for high coverage: Target at least 80% coverage for production code.
- Cover error paths: Ensure all
assert!andabortconditions are tested. - Don't chase 100%: Some code is trivial and doesn't need dedicated tests.
- Use coverage to find gaps: Review uncovered lines to identify missing tests.
- Run coverage in CI: Make coverage checks part of your continuous integration pipeline.