Go のテストコードを自動生成するスキル。
/plugin marketplace add shiiman/claude-code-plugins/plugin install shiiman-go@shiiman-claude-code-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Go のテストコードを自動生成するスキル。
対象の特定
ユーザーの指定から対象ファイル/関数を特定:
既存パターンの確認
# 既存のテストファイルを確認
ls *_test.go 2>/dev/null || ls **/*_test.go 2>/dev/null | head -5
確認項目:
テストコード生成
以下のベストプラクティスに従って生成:
func TestFunctionName(t *testing.T) {
t.Parallel() // 独立したテストの場合
tests := []struct {
name string
input InputType
expected OutputType
wantErr bool
}{
{
name: "正常系: 基本的な入力",
input: InputType{...},
expected: OutputType{...},
wantErr: false,
},
{
name: "異常系: 空の入力",
input: InputType{},
expected: OutputType{},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel() // サブテストも並行実行
got, err := FunctionName(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("FunctionName() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.expected) {
t.Errorf("FunctionName() = %v, want %v", got, tt.expected)
}
})
}
}
テスト実行確認
go test -v -run TestFunctionName ./path/to/package
| カテゴリ | 内容 |
|---|---|
| 正常系 | 基本的な入力、境界値 |
| 異常系 | 無効な入力、nil、空値 |
| エッジケース | 最大値、最小値、特殊文字 |
## テストコード生成完了
### 対象
- ファイル: {ファイル名}
- 関数: {関数名}
### 生成したテスト
- ファイル: {テストファイル名}
- テストケース数: {N}件
### テスト実行結果
{go test の出力}