testing-patterns
Installation
SKILL.md
Testing Patterns & Effect Abstraction
Short version: model your “effects” as traits, inject them, keep core logic pure, and provide real + fake implementations. That’s the idiomatic Rust way; free monads aren’t a thing here.
Pattern
- Define algebras as traits (ports).
- Implement adapters for prod (HTTP, DB, clock, FS) and for tests (fakes/mocks).
- Inject via generics (zero-cost, monomorphized) or trait objects (
dyn Trait) when you need late binding. - Keep domain functions pure; pass in effect results or tiny capability traits.
Minimal sync example
use std::time::{SystemTime, UNIX_EPOCH};