quality-unit-testing
9
总安装量
9
周安装量
#31850
全站排名
安装命令
npx skills add https://github.com/d-o-hub/rust-self-learning-memory --skill quality-unit-testing
Agent 安装分布
opencode
9
gemini-cli
9
claude-code
9
github-copilot
9
codex
9
kimi-cli
9
Skill 文档
Quality Unit Testing for Rust
Write tests that catch real bugs and provide deployment confidence.
Core Principles
Quality over coverage: Tests should catch real bugs, not just boost percentages.
Quick Reference
Naming: test_<function>_<scenario>_<expected>
#[test]
fn test_process_payment_insufficient_funds_returns_error()
#[tokio::test]
async fn test_withdraw_valid_amount_decreases_balance()
AAA Pattern (Arrange-Act-Assert)
#[test]
fn test_account_withdraw_decreases_balance() {
// Arrange
let mut account = Account::new(100);
// Act
let result = account.withdraw(30);
// Assert
assert!(result.is_ok());
assert_eq!(account.balance(), 70);
}
Isolation
â Mock: APIs, databases, file systems, external services â Don’t mock: Value types, pure functions, code under test
Single Responsibility
Each test verifies ONE behavior with ONE reason to fail.
Rust-Specific Patterns
// Async tests
#[tokio::test]
async fn test_async_operation() { /* ... */ }
// Result-based tests
#[test]
fn test_operation() -> anyhow::Result<()> { /* ... */ }
// Test builders
let episode = TestEpisodeBuilder::new()
.with_task("Test task")
.completed(true)
.build();
// RAII cleanup
struct TestDb(TempDir);
impl Drop for TestDb { fn drop(&mut self) { /* auto cleanup */ } }
Success Metrics
â Deploy without manual testing â Test failures pinpoint exact problems â Refactoring doesn’t break unrelated tests â Tests run in milliseconds
Workflow
Creating Tests:
- Understand the code behavior
- Identify risks
- Write failing test first (red-green-refactor)
- Apply AAA pattern
- Isolate dependencies
- Verify speed (milliseconds)
Reviewing Tests:
- Run analysis script
- Check naming conventions
- Ensure isolation
- Confirm single responsibility