Back to list
cemezgin

testing

by cemezgin

0🍴 0📅 Jan 25, 2026

SKILL.md


name: testing description: Testing patterns including table-driven tests, mock setup, and coverage requirements. Use when writing tests or setting up test infrastructure. userInvokable: true

Testing

References: Examples

Rules

RuleValue
Unit testsTestFunctionName
Integration testsTestIntegration*
Coverage85% minimum
Toolstestify/assert, gomock

Mock Generation

Example

Add at top of file with interfaces:

//go:generate mockgen -source=service.go -destination=service_mock.go -package=<pkg>

Run with:

make generate

Table-Driven Tests

Example

Use for testing multiple scenarios:

func TestFunction(t *testing.T) {
    tests := []struct {
        name     string
        input    string
        expected string
        wantErr  bool
    }{
        {name: "valid input", input: "foo", expected: "bar"},
        {name: "empty input", input: "", wantErr: true},
    }

    for _, tt := range tests {
        t.Run(tt.name, func(t *testing.T) {
            // test logic
        })
    }
}

Mock Setup

Example

func TestService(t *testing.T) {
    ctrl := gomock.NewController(t)
    defer ctrl.Finish()

    mockRepo := mocks.NewMockRepository(ctrl)
    mockRepo.EXPECT().
        FindByID(gomock.Any(), "id").
        Return(&Entity{}, nil)

    svc := NewService(mockRepo)
    // test...
}

Assertions

Example

Use testify/assert:

assert.NoError(t, err)
assert.Equal(t, expected, actual)
assert.Nil(t, result)
assert.NotNil(t, result)
assert.True(t, condition)
assert.Contains(t, slice, element)

Score

Total Score

45/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

0/5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon