test-runner について
自己学習型メモリープロジェクトで Rust のテストを実行、管理するスキルです。テスト分類、非同期テスト、カバレッジ、一般的な障害の調査を扱います。
主な機能
- 01ユニット、統合、ドキュメントテスト
- 02ミューテーションテストのコマンド
- 03非同期テストのパターン
- 04テスト分離の実践方法
- 05カバレッジ生成と障害対応
活用シーン
- 01種類を選んで Rust テストを実行
- 02非同期コードやタイムアウトのテスト
- 03競合状態やデータベースロックの調査
- 04HTML カバレッジレポートの生成
インストール
コマンドをコピーしてターミナルで実行します。
$
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 パターン:準備・実行・検証
- 単一責任:テストごとに 1 つの振る舞いを対象にします
- 命名:
test_<function>_<scenario>_<expected> - 速度:単体テスト 1 件あたり <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 がない | 非同期処理は必ず await します |
トラブルシューティング
| 問題 | 解決方法 |
|---|---|
| 競合状態 | cargo test -- --test-threads=1 |
| redb のロックエラー | テストごとに DB を分けます |
| DB 接続拒否 | TURSO_URL/TURSO_TOKEN を確認します |
カバレッジ
cargo llvm-cov --html --output-dir coverage
参考資料
- ADR-033:最新のテスト戦略
関連スキル:テスト設計には test-patterns、パフォーマンスを重視したテスト作業には test-optimization、失敗するテストスイートの原因診断には test-fix を使用します。
コメント
Markdown 対応