Context
Mostro Mobile is a Flutter application with critical security requirements for Bitcoin P2P trading. High-quality tests are essential for ensuring the safety of user funds and the reliability of the trading platform.
What is Mutation Testing?
Mutation testing is a technique to measure the quality and effectiveness of our test suite. It works by:
-
Creating mutants: The tool makes small, controlled changes (mutations) to the source code
- Example: Change
== to !=, + to -, true to false
- Example: Remove a line of code, change a condition boundary
- Example: Flip boolean conditions
-
Running the test suite: Tests are executed against each mutated version
-
Measuring survival rate:
- ✅ Mutant killed: Test failed → Good! Tests detected the artificial bug
- ❌ Mutant survived: Test passed → Bad! Tests did not catch the change
Mutation Score
Score = (Mutants killed / Total mutants) × 100
- > 80%: Excellent test coverage
- 50-80%: Acceptable, room for improvement
- < 50%: Tests are not effectively verifying behavior
Advantages for Mostro Mobile
- Security-critical code: Trading and key management code needs rigorous verification
- Detect weak tests: Find tests that "cover" code but do not actually verify correctness
- Force better assertions: Encourages specific, strict assertions instead of generic ones
- Find edge cases: Surviving mutants often reveal untested boundary conditions
- CI integration: Can fail builds if mutation score drops below threshold
- Documentation: Living documentation of what behavior is actually tested
Implementation Plan
Phase 1: Setup
-
Install mutant package
dart pub add --dev mutant
-
Configure mutation testing
Create mutant.yaml:
mutant:
targets:
- lib/
exclude:
- "**/*.g.dart"
- "**/generated/**"
- "**/*.freezed.dart"
rules:
- equality
- relational
- unary
- conditional_boundary
- literal
- method_call
threshold: 60 # Start conservative, increase gradually
Phase 2: CI Integration
Add to .github/workflows/flutter.yml:
- name: Run tests
run: flutter test
- name: Mutation Testing
run: dart run mutant
continue-on-error: true # Report only initially
- name: Upload mutation report
uses: actions/upload-artifact@v4
with:
name: mutation-report
path: mutation-report/
Phase 3: Gradual Improvement
Acceptance Criteria
Related
References
Context
Mostro Mobile is a Flutter application with critical security requirements for Bitcoin P2P trading. High-quality tests are essential for ensuring the safety of user funds and the reliability of the trading platform.
What is Mutation Testing?
Mutation testing is a technique to measure the quality and effectiveness of our test suite. It works by:
Creating mutants: The tool makes small, controlled changes (mutations) to the source code
==to!=,+to-,truetofalseRunning the test suite: Tests are executed against each mutated version
Measuring survival rate:
Mutation Score
Advantages for Mostro Mobile
Implementation Plan
Phase 1: Setup
Install mutant package
Configure mutation testing
Create
mutant.yaml:Phase 2: CI Integration
Add to
.github/workflows/flutter.yml:Phase 3: Gradual Improvement
Acceptance Criteria
mutantto dev_dependencies in pubspec.yamlRelated
References