test-generator
ユーザーが「テストを書いて」「テストケースを追加」「テストカバレッジを上げて」「テストが足りない」等と要求した時に発動。 既存の関数に対して包括的なテストケース(正常系・異常系・境界値)を自動生成する。 go testで実行可能な形式で出力し、カバレッジを向上させる。
When & Why to Use This Skill
The test-generator skill is an automated tool designed for Go (Golang) developers to enhance software reliability through comprehensive unit test generation. It intelligently analyzes existing codebases to identify untested functions and automatically creates robust, table-driven test cases covering normal operations, boundary conditions, and error scenarios. By integrating with the 'go test' suite, it helps developers significantly increase code coverage and ensure high-quality, bug-free deployments.
Use Cases
- Increasing code coverage: Automatically identifying functions with low coverage and generating the necessary test files to meet project requirements.
- Edge case validation: Generating tests for complex boundary conditions such as nil pointers, empty arrays, and maximum/minimum values to prevent runtime crashes.
- Regression testing: Quickly creating a suite of tests for existing functions before refactoring to ensure that no new bugs are introduced.
- Standardizing test suites: Converting manual or inconsistent tests into professional, table-driven Go tests that follow industry best practices.
| name | test-generator |
|---|---|
| description | >- |
| allowed-tools | Read, Write, Edit, Grep, Glob, Bash |
手順
- 対象関数の特定: ユーザー指定または全関数から、テストが不足している関数を特定(Grep/Glob)
- 既存テスト分析:
*_test.goを読み込み、既にカバーされているケースを確認 - カバレッジ確認:
go test -coverでカバレッジの穴を特定 - 不足ケースの生成: 以下のカテゴリでテストケースを追加
- 正常系(典型的な入力)
- 境界値(空配列、nil、0、負数、最大値)
- 異常系(エラーケース)
- テストコード追加: 既存の
*_test.goファイルに追加、または新規作成 - 検証:
go test -v -coverで全テストがパスし、カバレッジが向上したことを確認 - レポート: 追加したテストケースの数とカバレッジの改善度を報告
ベストプラクティス
- テスト関数名は
Test<関数名><ケース名>の形式(例:TestSumEmpty,TestSumNegative) - Table-Driven Tests を活用して、複数ケースを効率的に記述
- エラーメッセージは具体的に(期待値と実際の値を明示)
- 既存のテストスタイルに合わせる