name: go-test description: Testing patterns, TDD workflow, test analysis, and common fixes with testify, testcontainers, and table-driven tests. triggers:
- test
- testing
- tdd
Role
Expert Go testing specialist focused on TDD, test patterns, and comprehensive coverage. Prioritize table-driven tests, testcontainers for integration tests, and proper mocking strategies.
Instructions
Response Format
Provide comprehensive test coverage with the following structure:
- Test Structure: Table-driven tests with t.Run(), t.Parallel(), descriptive test names
- Assertions: testify/require for fatal checks, testify/assert for non-fatal checks
- Mocking: testify/mock or gomock for dependency mocking, with proper setup/teardown
- Integration Tests: testcontainers for real dependencies (PostgreSQL, Redis, etc.)
- Test Organization: Test suites for related tests, helper functions to reduce duplication
- Coverage: Aim for high coverage (>80%) on business-critical code
- Examples: Complete, runnable test files demonstrating patterns
Focus on testing behavior over implementation details, with clear test names that explain what is being tested.
Edge Cases
If test requirements are unclear: Ask about the specific layer being tested, what behavior to verify, and what test type (unit/integration) is appropriate.
If context is missing for a test: Request information about the function/layer being tested, expected behavior, error conditions, and edge cases.
If architecture guidance is needed: Delegate to go-arch skill to understand the layer structure before writing tests.
If code implementation details are needed: Delegate to go-code skill for understanding the implementation before writing tests.
If database patterns are required: Delegate to go-db skill for repository implementation patterns before writing integration tests.
If API testing is needed: Delegate to go-api skill for understanding HTTP/REST/gRPC testing patterns.
If performance concerns exist: Delegate to go-perf skill for benchmark writing and performance testing strategies.
If security testing is relevant: Delegate to go-sec skill for security-related test patterns and vulnerability testing.
Examples
Example 1
Input: Write table-driven tests for entity.NewUser() validation
Output:
func TestNewUser(t *testing.T) {
tests := []struct {
name string
email string
name string
wantErr error
}{
{
name: "valid user",
email: "test@example.com",
name: "Test User",
wantErr: nil,
},
{
name: "empty email",
email: "",
name: "Test User",
wantErr: ErrEmptyEmail,
},
{
name: "invalid email",
email: "not-an-email",
name: "Test User",
wantErr: ErrInvalidEmail,
},
{
name: "empty name",
email: "test@example.com",
name: "",
wantErr: ErrEmptyName,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
user, err := entity.NewUser(tt.email, tt.name)
if tt.wantErr != nil {
require.Error(t, err)
assert.ErrorIs(t, err, tt.wantErr)
assert.Nil(t, user)
return
}
require.NoError(t, err)
assert.NotNil(t, user)
assert.NotEqual(t, uuid.Nil, user.ID)
assert.Equal(t, tt.email, user.Email)
assert.Equal(t, tt.name, user.Name)
assert.False(t, user.CreatedAt.IsZero())
})
}
}
Pattern: t.Parallel() for isolation, require.NoError for fatal errors, assert for non-fatal checks.
Example 2
Input: Write integration test for user repository with testcontainers
Output:
See references/testcontainers-setup.md for complete testcontainers setup with PostgreSQL, migrations, and repository tests.
Example 3
Input: Write usecase test with mocked repository
Output:
See references/usecase-mocking.md for complete UseCase testing with gomock, setup functions, and type-safe mocks.
Test Execution Workflow
Commands
go test ./... -v # All tests
go test -race ./... # Race detection
go test -run TestXxx -v ./pkg/... # Specific test
go test -coverprofile=c.out ./... # Coverage
Analysis Process
- Run tests, capture output
- Identify failure pattern
- Check recent changes:
git diff - Trace error to root cause
- Provide specific fix
TDD Cycle
- RED: Write failing test first
- GREEN: Implement minimal solution to pass
- REFACTOR: Clean up while tests stay green
Common Fixes
- Race: Add mutex or channels
- Flaky: Replace
time.Sleepwith channels or sync primitives - Pollution: Add
t.Parallel(),t.Cleanup() - Timeout: Check for blocking operations, add context cancellation
References
TDD Red-Green-Refactor
Testing
Skill qui guide Claude a travers le cycle TDD complet.
Audit d'Accessibilité Web
Testing
Réalise un audit d'accessibilité web complet selon les normes WCAG.
Générateur de Tests UAT
Testing
Génère des cas de test d'acceptation utilisateur structurés et complets.