mockery-suite-tests
БесплатноБез исполняемых скриптовНе проверенUse when writing Go tests that need test doubles or cover multiple cases - detect the repo's mocking approach (Mockery v3, gomock, hand-written testify mocks…
от makifbaysal★ 123 звезды на GitHubОб этом скилле
Go Test Doubles & Table Tests
Overview
Table-driven tests and real-Postgres repository-adapter tests are non-negotiable everywhere. How test doubles are produced is not: follow the repository's own convention (rule repo-conventions-win) rather than importing Mockery into a repo that hand-writes testify mocks or uses gomock.
Core principle: multi-case behaviour is a table; a repository adapter test runs against real Postgres, never a mocked driver; mocks exist only at port boundaries.
Detect the repo's mocking approach first
ls .mockery.y*ml 2>/dev/null
grep -rlE 'Code generated by mockery|go.uber.org/mock' --include='*.go' . | head -3
.mockery.ymlor files headed "Code generated by mockery" → Mockery v3: regenerate, don't hand-edit (see below).go.uber.org/mockimports → gomock: regenerate withmockgenper the repo'sgo:generatedirective, don't hand-edit.- Neither, but a test file defines
type mockFoo structimplementing a port → the repo hand-writes testify mocks (or fakes). Follow that style; do not introduce a generator the repo doesn't already have. TaskTrooper's own server does exactly this (server/internal/port/mocks/llm_client.go).
Mockery v3 (when the repo already uses it)
- Mocks come from the port interfaces, generated by Mockery v3. Names and location come from
.mockery.yml; v3's defaults areMock<Interface>inmocks_test.goinside the source package, constructorNewMock<Interface>(t)— don't assume a different naming scheme without checking the config. - Regenerate with the repo's own command (
mockery,go generate ./..., ormake mocks) — never hand-edit a generated mock. - Install Mockery from a pinned release binary (GitHub Releases, any OS) or
brew install mockeryon macOS; the project's own docs say not togo install mockery@latest. - A v2
.mockery.yamlmigrates withmockery migrate; don't hand-port the config. - v3 generates an
expecterAPI — use the typedEXPECT()methods, not rawOn("MethodName", ...)string calls, so a renamed method breaks compilation instead of silently passing.
repo := mocks.NewMockTaskRepository(t) // generated constructor, auto-asserts on cleanup
repo.EXPECT().Create(mock.Anything, task).Return(nil).Once()
svc := NewTaskService(repo)
Table-driven tests (every repo, every approach)
Every function with more than one case is a table. One row = one behavior with a descriptive name.
func TestTaskService_Create(t *testing.T) {
tests := []struct {
name string
title string
setup func(*mockTaskRepository)
wantErr error
}{
{name: "valid title persists",
title: "Report",
setup: func(r *mockTaskRepository) { r.onCreate(nil) }},
{name: "blank title rejected before DB",
title: " ",
setup: func(r *mockTaskRepository) { /* no expectation: repo must NOT be called */ },
wantErr: domain.ErrInvalidTitle},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
repo := newMockTaskRepository(t)
tt.setup(repo)
_, err := NewTaskService(repo).Create(t.Context(), tt.title)
if !errors.Is(err, tt.wantErr) {
t.Fatalf("got %v, want %v", err, tt.wantErr)
}
})
}
}
Cover success, every error path, and edges (empty, not-found, conflict) as rows. A blank-title row that sets NO expectation proves the repo is never touched on invalid input. Use a testify suite (suite.Suite + SetupTest) only where the repo already uses one for shared fixtures — suites don't support t.Parallel(), so don't introduce one into a repo that parallelizes its tests.
Repository adapter tests run against real Postgres
A repository adapter test (the thing implementing the port against pgx/database/sql) is never unit-tested against a mocked driver — it proves nothing about the actual SQL. Use the repo's own test-database harness, or testcontainers-go modules/postgres with the repo's migrations applied, and assert on rows actually read back.
Modern Go testing
t.Context()(Go ≥1.24) instead ofcontext.Background()in tests — it's canceled on test cleanup.testing/synctest(Go ≥1.25) for deterministic tests of timers, timeouts and goroutine scheduling instead of realtime.Sleep.go test -race -count=1 ./...for anything touching concurrency — run it, don't just suggest it.
Rules
- Mock ONLY at port boundaries (repositories, external clients). Domain logic uses real domain values — no mocks.
- Assert on behavior and returned values, not on internal call ordering — over-specified expectations break on every refactor. Use
.Once()/.Times(n)(or the gomock/hand-written equivalent) only where the count is the behavior under test. - Keep the suite green and output pristine: a happy-path test that logs errors hides real failures.
- Never add a
Установить mockery-suite-tests в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл mockery-suite-tests?
Use when writing Go tests that need test doubles or cover multiple cases - detect the repo's mocking approach (Mockery v3, gomock, hand-written testify mocks, fakes), table-driven cases, testify suites when the repo uses them, and real-Postgres tests for repository adapters
Как установить скилл mockery-suite-tests?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл mockery-suite-tests запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic