Unit & Integration Testing
This topic covers the full spectrum of testing in software engineering, from isolated unit tests through integration tests that verify real system behavior. All examples use Rust.
Contents
- Unit Testing Fundamentals — What makes a good unit test, the AAA pattern, test naming, Rust testing mechanics, assert macros,
#[should_panic]. - Test-Driven Development — The Red-Green-Refactor cycle, step-by-step TDD in Rust, when TDD works well and when it is awkward, anti-patterns.
- Property-Based Testing — Properties vs. examples,
proptestin Rust, custom strategies, shrinking, real bugs found by property tests. - Mocking and Test Doubles — Stubs, mocks, fakes, spies. Trait-based dependency injection in Rust, the
mockallcrate, when to mock vs. use real implementations. - Integration Testing — Testing with real databases (
sqlxtest fixtures), API endpoint testing, test containers, test isolation strategies. - Code Coverage and Metrics — Line vs. branch vs. function coverage, the coverage trap, useful targets (70-80%),
cargo-tarpaulin,nextest.
Diagrams

