| name | go-test-generator |
| description | Goのテストコードを生成する際に使用。テーブル駆動テスト、testify/assert使用、命名規則TestStructName_MethodNameを適用。Goのユニットテスト、統合テストを書く場合に使用。 |
| allowed-tools | Read, Glob |
Go テスト生成パターン
このプロジェクトのGoテスト実装パターンを定義します。
命名規則
- ファイル名:
*_test.go
- 関数名:
TestStructName_MethodName または TestFunctionName
- パッケージ名:
{package}_test (外部テスト) または {package} (内部テスト)
使用ライブラリ
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
assert: テスト失敗しても続行
require: テスト失敗で即座に中断
参照ファイル
テスト実装の参照:
server/internal/repository/user_repository_test.go - Repository テスト
server/internal/db/sharding_test.go - シャーディングテスト
server/test/integration/ - 統合テスト
テストユーティリティ:
server/test/testutil/ - テストヘルパー
コードパターン
1. 基本的なテスト
func {
expected :=
actual := SomeFunction()
assert.Equal(t, expected, actual)
}