go-testing
БесплатноБез исполняемых скриптовНе проверенGo testing with go test, testify, and gomock. Covers unit tests, table-driven tests, benchmarks, mocking, and test coverage. USE WHEN: user mentions "go…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Go Testing Core Knowledge
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:gofor comprehensive documentation.
Full Reference: See advanced.md for HTTP Testing, Benchmarks, Test Helpers, Test Fixtures, Integration Tests, Parallel Tests, and Test Coverage.
When NOT to Use This Skill
- JavaScript/TypeScript Projects - Use
vitestorjest - Java Projects - Use
junitfor Java testing - Python Projects - Use
pytestfor Python - E2E Browser Testing - Use Playwright or Selenium
- Rust Projects - Use
rust-testingskill
Basic Testing
Unit Tests
// math.go
package math
func Add(a, b int) int {
return a + b
}
func Divide(a, b float64) (float64, error) {
if b == 0 {
return 0, errors.New("division by zero")
}
return a / b, nil
}
// math_test.go
package math
import "testing"
func TestAdd(t *testing.T) {
result := Add(2, 3)
if result != 5 {
t.Errorf("Add(2, 3) = %d; want 5", result)
}
}
func TestDivide(t *testing.T) {
result, err := Divide(10, 2)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if result != 5.0 {
t.Errorf("Divide(10, 2) = %f; want 5.0", result)
}
}
func TestDivideByZero(t *testing.T) {
_, err := Divide(10, 0)
if err == nil {
t.Error("expected error for division by zero")
}
}
Running Tests
# Run all tests
go test ./...
# Run tests in current package
go test
# Run specific test
go test -run TestAdd
# Verbose output
go test -v
# Run with coverage
go test -cover
# Generate coverage report
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
# Run tests with race detector
go test -race
# Set timeout
go test -timeout 30s
Table-Driven Tests
func TestAddTableDriven(t *testing.T) {
tests := []struct {
name string
a, b int
expected int
}{
{"positive numbers", 2, 3, 5},
{"negative numbers", -1, -1, -2},
{"zero", 0, 0, 0},
{"mixed", -1, 1, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := Add(tt.a, tt.b)
if result != tt.expected {
t.Errorf("Add(%d, %d) = %d; want %d",
tt.a, tt.b, result, tt.expected)
}
})
}
}
func TestDivideTableDriven(t *testing.T) {
tests := []struct {
name string
a, b float64
expected float64
expectErr bool
}{
{"normal division", 10, 2, 5, false},
{"division by zero", 10, 0, 0, true},
{"negative result", -10, 2, -5, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := Divide(tt.a, tt.b)
if tt.expectErr {
if err == nil {
t.Error("expected error, got nil")
}
return
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if result != tt.expected {
t.Errorf("got %f; want %f", result, tt.expected)
}
})
}
}
Testify
go get github.com/stretchr/testify
Assert Package
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestWithAssert(t *testing.T) {
// Equality
assert.Equal(t, 5, Add(2, 3))
assert.NotEqual(t, 6, Add(2, 3))
// Boolean
assert.True(t, true)
assert.False(t, false)
// Nil checks
assert.Nil(t, nil)
assert.NotNil(t, "value")
// Error checks
_, err := Divide(10, 0)
assert.Error(t, err)
assert.EqualError(t, err, "division by zero")
result, err := Divide(10, 2)
assert.NoError(t, err)
assert.Equal(t, 5.0, result)
// Contains
assert.Contains(t, "hello world", "world")
assert.Contains(t, []int{1, 2, 3}, 2)
// Length
assert.Len(t, []int{1, 2, 3}, 3)
// Panics
assert.Panics(t, func() { panic("boom") })
}
Require Package
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestWithRequire(t *testing.T) {
// require stops test on failure (unlike assert)
result, err := Divide(10, 2)
require.NoError(t, err) // Test stops here if err != nil
require.Equal(t, 5.0, result)
}
Suite Package
import (
"testing"
"github.com/stretchr/testify/suite"
)
type UserServiceTestSuite struct {
suite.Suite
db *sql.DB
service *UserService
}
func (s *UserServiceTestSuite) SetupSuite() {
// Run once before all tests
var err error
s.db, err = sql.Open("postgres", "test-connection")
s.Require().NoError(err)
}
func (s *UserServiceTestSuite) TearDownSuite() {
// Run once after all tests
s.db.Close()
}
func (s *UserServiceTestSuite) SetupTest() {
// Run before each test
s.s
Установить go-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditBashВложенные файлы
FAQ
Что делает скилл go-testing?
Go testing with go test, testify, and gomock. Covers unit tests, table-driven tests, benchmarks, mocking, and test coverage. USE WHEN: user mentions "go test", "golang test", "testify", asks about "table-driven test", "gomock", "go benchmark", "testing.T", "httptest" DO NOT USE FOR: JavaScript/TypeScript - use `vitest` or `jest`; Java - use `junit`; Python - use `pytest`; E2E browser tests - use Playwright; Rust - use `rust-testing`
Как установить скилл go-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл go-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic