testkit-async 🧰
Practical testing tools for async Rust
testkit-async is a comprehensive testing toolkit for async Rust code. It provides time control, deterministic execution, failure injection, and rich assertions to make async testing fast, reliable, and easy.
🎯 Why testkit-async?
The Problem
Testing async code in Rust is frustrating:
async
Common issues:
- ❌ Tests are slow (waiting for real time)
- ❌ Tests are flaky (race conditions, timing issues)
- ❌ Tests are hard to write (complex async coordination)
- ❌ Tests are unpredictable (non-deterministic execution)
The Solution
use *;
async
✨ Features (Planned)
- ⏱️ Mock Clock - Control time without waiting
- 🎮 Deterministic Executor - Control task execution order
- 💥 Failure Injection - Simulate errors, timeouts, network issues
- 🔍 Async Assertions - Fluent API for testing streams and futures
- 🎯 Sync Points - Coordinate multiple tasks precisely
- 📊 Test Utilities - Mocks, spies, and test helpers
🚧 Status
Work in Progress - Early development
Current version: 0.1.0-alpha
🆚 Comparison with Existing Tools
What Already Exists
| Tool | What It Does | What's Missing |
|---|---|---|
| async-test | Attribute macro for async tests | ❌ No time control❌ No execution control❌ Just a macro wrapper |
| tokio-test | Tokio testing utilities | ⚠️ Tokio-specific only❌ Limited time control❌ No failure injection |
| futures-test | Futures test utilities | ❌ No mock clock❌ Low-level only❌ Not ergonomic |
| mockall | General mocking | ❌ Not async-aware❌ Verbose for async |
What testkit-async Provides
| Feature | testkit-async | tokio-test | futures-test | async-test |
|---|---|---|---|---|
| Mock Clock | ✅ Full control | ⚠️ Limited | ❌ | ❌ |
| Deterministic Execution | ✅ | ❌ | ❌ | ❌ |
| Failure Injection | ✅ | ❌ | ❌ | ❌ |
| Async Assertions | ✅ | ❌ | ❌ | ❌ |
| Sync Points | ✅ | ❌ | ❌ | ❌ |
| Runtime Agnostic | ✅ | ❌ Tokio only | ✅ | ✅ |
| Ergonomic API | ✅ | ⚠️ | ❌ | ⚠️ |
Key Differentiators:
- Complete Time Control - Not just pause/resume, but full virtual time
- Deterministic Testing - Control exact execution order of tasks
- Chaos Engineering - Built-in failure injection and network simulation
- High-Level API - Ergonomic, not low-level primitives
📚 Quick Examples (Planned API)
Time Control
use *;
async
Controlled Concurrency
use *;
async
Failure Injection
use FailureInjector;
async
Async Assertions
use *;
async
Mock Async Dependencies
use *;
async
🎯 Use Cases
Fast Test Suites
// Before: Test suite takes 5 minutes (lots of sleeps/timeouts)
// After: Test suite takes 5 seconds (virtual time)
Deterministic Tests
// Before: Flaky tests due to race conditions
// After: Deterministic execution, reproducible failures
Chaos Engineering
// Test resilience to:
// - Network timeouts
// - Random failures
// - Slow responses
// - Connection drops
Integration Testing
// Test complex async interactions:
// - Multiple services communicating
// - Event-driven systems
// - Stream processing pipelines
📦 Installation
# Not yet published - coming soon!
# Or in Cargo.toml:
🗺️ Roadmap
Phase 1: Time Control (Current)
- Mock clock implementation
- Time advancement APIs
- Integration with tokio::time
- Pause/resume time
Phase 2: Execution Control
- Test executor
- Sync points
- Step-by-step execution
- Task inspection
Phase 3: Chaos Engineering
- Failure injector
- Network simulator
- Latency injection
- Resource exhaustion simulation
Phase 4: Assertions & Utilities
- Async assertion macros
- Stream testing helpers
- Mock trait generation
- Snapshot testing for async
Phase 5: Ecosystem Integration
- Tokio integration
- async-std integration
- smol integration
- Runtime-agnostic core
🎨 Design Philosophy
Ergonomics First:
- Simple for common cases
- Powerful for complex scenarios
- Minimal boilerplate
Determinism:
- Reproducible test results
- No timing-dependent failures
- Controlled execution order
Fast:
- Tests run at CPU speed, not wall-clock time
- Parallel-friendly
- Efficient mocking
Composable:
- Mix and match features
- Works with existing tools
- Not all-or-nothing
🤝 Contributing
Contributions welcome! This project is in early stages.
Priority areas:
- Mock clock implementation
- Test executor design
- Failure injection patterns
- Documentation and examples
- Runtime compatibility
📝 License
MIT OR Apache-2.0
🙏 Acknowledgments
Inspired by:
- tokio-test - Tokio testing utilities
- futures-test - Futures testing primitives
- async-std - Async runtime ideas
- Testing frameworks from other languages:
- Python's pytest-asyncio
- JavaScript's fake-timers
- Go's testing patterns
🔗 Related Projects
testkit-async - Making async testing practical 🧰
Status: 🚧 Pre-alpha - Core architecture in design
Star ⭐ this repo to follow development!