关于 test-runner
用于在自学习记忆项目中运行和管理 Rust 测试的技能,涵盖测试分类、异步测试、覆盖率及常见故障排查。
主要功能
- 01单元、集成和文档测试
- 02变异测试命令
- 03异步测试模式
- 04测试隔离实践
- 05覆盖率生成与故障排查
适用场景
- 01运行指定类别的 Rust 测试
- 02测试异步代码和超时
- 03排查竞态条件或数据库锁
- 04生成 HTML 覆盖率报告
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ d-o-hub/ rust-self-learning-memory --skill test-runner安装后在 Claude Code 中输入/test-runner确认已加载。
附带文件evals/evals.json
详细介绍
测试运行器
执行和管理自学习记忆项目的 Rust 测试。
命令
# Unit tests (fast, <30s)
cargo nextest run --lib
# Integration tests
cargo nextest run --test '*'
# Full suite
cargo nextest run --all
cargo test --doc # doctests (nextest unsupported)
# Quality gates (coverage threshold 90%)
./scripts/quality-gates.sh
测试类别
| 类别 | 命令 | 范围 |
|---|---|---|
| 单元 | cargo nextest run --lib | 单个函数 |
| 集成 | cargo nextest run --test '*' | 端到端工作流 |
| 文档 | cargo test --doc | 文档示例 |
| 变异 | cargo mutants -p do-memory-core | 测试有效性 |
最佳实践
- 隔离:每个测试都相互独立
- AAA 模式:准备(Arrange)- 执行(Act)- 断言(Assert)
- 单一职责:每个测试只验证一种行为
- 命名:
test_<function>_<scenario>_<expected> - 速度:每个单元测试 <1s
异步测试
#[tokio::test]
async fn test_episode() { let result = async_fn().await; }
#[tokio::test(start_paused = true)]
async fn test_timeout() { /* paused clock */ }
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn test_concurrent() { /* parallel ops */ }
| 不推荐 | 推荐 |
|---|---|
std::thread::sleep() | tokio::time::sleep().await |
缺少 .await | 始终等待异步操作完成 |
故障排查
| 问题 | 解决方法 |
|---|---|
| 竞态条件 | cargo test -- --test-threads=1 |
| redb 锁错误 | 为每个测试使用单独的数据库 |
| 数据库连接被拒绝 | 检查 TURSO_URL/TURSO_TOKEN |
覆盖率
cargo llvm-cov --html --output-dir coverage
参考资料
- ADR-033:现代测试策略
相关技能:使用 test-patterns 设计测试,使用 test-optimization 开展以性能为重点的测试工作,使用 test-fix 诊断测试套件失败问题。
评论
支持 Markdown