golang-testing

Solid

テスト駆動開発とGoコードの高品質を保証するための包括的なテスト戦略。

Testing & QA 196,640 stars 30253 forks Updated 2 days ago MIT

Install

View on GitHub

Quality Score: 92/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Go テスト テスト駆動開発(TDD)とGoコードの高品質を保証するための包括的なテスト戦略。 ## いつ有効化するか - 新しいGoコードを書くとき - Goコードをレビューするとき - 既存のテストを改善するとき - テストカバレッジを向上させるとき - デバッグとバグ修正時 ## 核となる原則 ### 1. テスト駆動開発(TDD)ワークフロー 失敗するテストを書き、実装し、リファクタリングするサイクルに従います。 ```go // 1. テストを書く(失敗) func TestCalculateTotal(t *testing.T) { total := CalculateTotal([]float64{10.0, 20.0, 30.0}) want := 60.0 if total != want { t.Errorf("got %f, want %f", total, want) } } // 2. 実装する(テストを通す) func CalculateTotal(prices []float64) float64 { var total float64 for _, price := range prices { total += price } return total } // 3. リファクタリング // テストを壊さずにコードを改善 ``` ### 2. テーブル駆動テスト 複数のケースを体系的にテストします。 ```go func TestAdd(t *testing.T) { tests := []struct { name string a, b int want int }{ {"positive numbers", 2, 3, 5}, {"negative numbers", -2, -3, -5}, {"mixed signs", -2, 3, 1}, {"zeros", 0, 0, 0}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := Add(tt.a, tt.b) if got != tt.want { t.Errorf("Add(%d, %d) = %d; want %d", tt.a, tt.b, got, tt.want) } }) } } ``` ### 3. サブテスト サブテストを使用した論理的なテストの構成。 ```go func TestUser(t *testing.T) { t.Run("validation", func(t *testing.T) { t.Run("empty email", func(t *testing.T) { user := User{Email: ""} if err := user.Validate(); err == nil { ...

Details

Author
affaan-m
Repository
affaan-m/everything-claude-code
Created
4 months ago
Last Updated
2 days ago
Language
JavaScript
License
MIT

Integrates with

Related Skills