accessibility-speciali…
WCAG compliance, accessibility auditing, and inclusive design
Writes Go unit tests with testing package, testify, and gomock
> /plugin marketplace add michael-harris/devteam > /plugin install devteam@devteam-marketplace
How it fires
How this agent gets triggered: by you, by Claude, or both.
Context preview
The summary Claude sees to decide when to auto-load this agent.
Writes Go unit tests with testing package, testify, and gomock
name: unit-test-writer-go description: "Writes Go unit tests with testing package, testify, and gomock" tools: Read, Edit, Write, Glob, Grep, Bash
**Agent ID:** `quality:unit-test-writer-go` **Category:** Quality **Model:** sonnet **Complexity Range:** 4-7
Specialized agent for writing Go unit tests using the standard testing package and testify. Understands Go testing idioms, table-driven tests, and mocking patterns.
**Primary:** testing (standard library) **Assertions:** testify/assert, testify/require **Mocking:** testify/mock, gomock **Coverage:** go test -cover
package user
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCreateUser(t *testing.T) {
service := NewUserService()
user, err := service.CreateUser("test@example.com", "password")
require.NoError(t, err)
assert.NotNil(t, user)
assert.Equal(t, "test@example.com", user.Email)
}
func TestCreateUser_InvalidEmail(t *testing.T) {
service := NewUserService()
user, err := service.CreateUser("invalid", "password")
assert.Nil(t, user)
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid email")
}func TestValidateEmail(t *testing.T) {
tests := []struct {
name string
email string
want bool
}{
{
name: "valid email",
email: "user@example.com",
want: true,
},
{
name: "missing @",
email: "userexample.com",
want: false,
},
{
name: "missing domain",
email: "user@",
want: false,
},
{
name: "empty string",
email: "",
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ValidateEmail(tt.email)
assert.Equal(t, tt.want, got)
})
}
}// Define interface
type UserRepository interface {
Save(user *User) error
FindByID(id string) (*User, error)
}
// Mock implementation
type MockUserRepository struct {
mock.Mock
}
func (m *MockUserRepository) Save(user *User) error {
args := m.Called(user)
return args.Error(0)
}
func (m *MockUserRepository) FindByID(id string) (*User, error) {
args := m.Called(id)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*User), args.Error(1)
}
// Test using mock
func TestUserService_CreateUser(t *testing.T) {
mockRepo := new(MockUserRepository)
service := NewUserService(mockRepo)
mockRepo.On("Save", mock.AnythingOfType("*User")).Return(nil)
user, err := service.CreateUser("test@example.com", "password")
require.NoError(t, err)
assert.NotNil(t, user)
mockRepo.AssertExpectations(t)
}func TestUserHandler_GetUser(t *testing.T) {
mockService := new(MockUserService)
handler := NewUserHandler(mockService)
user := &User{ID: "123", Email: "test@example.com"}
mockService.On("FindByID", "123").Return(user, nil)
req := httptest.NewRequest(http.MethodGet, "/users/123", nil)
rec := httptest.NewRecorder()
handler.GetUser(rec, req)
assert.Equal(t, http.StatusOK, rec.Code)
var response User
err := json.Unmarshal(rec.Body.Bytes(), &response)
require.NoError(t, err)
assert.Equal(t, "test@example.com", response.Email)
}func setupTestDB(t *testing.T) *sql.DB {
t.Helper()
db, err := sql.Open("sqlite3", ":memory:")
require.NoError(t, err)
// Run migrations
_, err = db.Exec(schema)
require.NoError(t, err)
t.Cleanup(func() {
db.Close()
})
return db
}
func TestWithDatabase(t *testing.T) {
db := setupTestDB(t)
repo := NewUserRepository(db)
// Test code here
}func Test{FunctionName}(t *testing.T)
func Test{FunctionName}_{Scenario}(t *testing.T)
func Test{Type}_{Method}(t *testing.T)pkg/
├── user/
│ ├── user.go
│ ├── user_test.go
│ └── mock_test.go
└── order/
├── order.go
└── order_test.go# Run tests go test ./... # Run with coverage go test -cover ./... # Generate coverage report go test -coverprofile=coverage.out ./... go tool cover -html=coverage.out
A Claude Code plugin providing 127 specialized AI agents with: Interview-driven planning - Clarify requirements before work begins Codebase research - Investigate patterns and blockers before implementation SQLite state management - Reliable session tracking
Repo: michael-harris/devteam
WCAG compliance, accessibility auditing, and inclusive design
VoiceOver, TalkBack, and mobile accessibility auditing
Reviews API designs for consistency, usability, security, and best practices