mockery
БесплатноБез исполняемых скриптовНе проверенMock generation workflow for go-crypto-wallet. Activate whenever a developer asks to generate a mock for a new interface, add test coverage that requires a…
от hiromaily★ 129 звёзд на GitHubОб этом скилле
Mockery Mock Generation Workflow
When to Activate This Skill
- A new interface is added to
internal/application/ports/ - A test file contains a manually-written mock/stub for a ports interface
- A developer asks to add mock coverage for an existing ports interface
- A test needs to replace
On(...).Return(...)setup on a hand-rolled struct with generated mock expectations
Placement Convention
Mocks live in the infrastructure layer, beside the concrete implementations:
Interface package (application/ports/) |
Mock output directory (infrastructure/) |
|---|---|
ports/api/btc/ |
infrastructure/api/btc/mocks/ |
ports/api/eth/ |
infrastructure/api/eth/mocks/ |
ports/api/xrp/ |
infrastructure/api/xrp/mocks/ |
ports/file/ |
infrastructure/storage/file/transaction/mocks/ |
ports/repository/cold/ |
infrastructure/repository/cold/mocks/ |
ports/repository/watch/ |
infrastructure/repository/watch/mocks/ |
Pattern: ports/<layer>/<pkg>/ → infrastructure/<layer>/<pkg>/mocks/
Step-by-Step Workflow
- Locate the interface — find the Go file in
internal/application/ports/that defines the interface. - Determine the target directory — use the placement convention table above to identify the
dirvalue. - Add or update
.mockery.yaml— append the interface name under its package entry (or add a new package entry if none exists). See the template below. - Run
make mockery— regenerates all mocks in one pass. Never create or edit mock files manually. - Verify — run
make go-lintandmake check-buildto confirm the generated code compiles cleanly. - Update tests — replace any manual stub usage with
NewMock*(t)+.EXPECT()builder calls.
.mockery.yaml Entry Template
Adding an interface to an existing package entry
packages:
github.com/hiromaily/go-crypto-wallet/internal/application/ports/<layer>/<pkg>:
config:
dir: "internal/infrastructure/<layer>/<pkg>/mocks"
pkgname: "mocks"
interfaces:
ExistingInterface:
MyNewInterface: # ← append here
Adding a brand-new package entry
github.com/hiromaily/go-crypto-wallet/internal/application/ports/<layer>/<pkg>:
config:
dir: "internal/infrastructure/<layer>/<pkg>/mocks"
pkgname: "mocks"
interfaces:
MyNewInterface:
The global settings (filename, structname, template, formatter) are already configured in .mockery.yaml and apply automatically — do not override them per-package.
Generated File Conventions
| Setting | Value |
|---|---|
| Filename | mock_<interface_name_snakecase>.go |
| Struct name | Mock<InterfaceName> |
| Constructor | NewMock<InterfaceName>(t) |
| Package | mocks |
| Header | // Code generated by mockery; DO NOT EDIT. |
Test Usage — Before / After
Before (manual stub — do NOT write this)
// ❌ Manually-written stub in a test file
type stubAccountRepo struct{}
func (s *stubAccountRepo) GetOneMaxID(accountType domainAccount.AccountType) (*domainKey.BTCAccountKey, error) {
return &domainKey.BTCAccountKey{Index: 0}, nil
}
func TestFoo(t *testing.T) {
repo := &stubAccountRepo{}
uc := NewUseCase(repo)
// ...
// Manual assertion:
// (no automatic call-count verification)
}
After (mockery-generated mock — always use this)
// ✅ Import the generated mocks package
import coldmocks "github.com/hiromaily/go-crypto-wallet/internal/infrastructure/repository/cold/mocks"
func TestFoo(t *testing.T) {
repo := coldmocks.NewMockBTCAccountKeyRepositorier(t) // registers cleanup automatically
repo.EXPECT().
GetOneMaxID(domainAccount.AccountTypeDeposit).
Return(&domainKey.BTCAccountKey{Index: 0}, nil)
uc := NewUseCase(repo)
// ...
// AssertExpectations is called automatically via t.Cleanup — do NOT call it manually
}
Key differences:
NewMock*(t)registerst.Cleanup(func() { mock.AssertExpectations(t) })automatically — never callAssertExpectationsmanually..EXPECT().Method(args...).Return(values...)provides type-safe, call-count-verified expectations.- The generated mock handles all type assertions internally — no
args.Get(0).(*Type)boilerplate.
Exceptions — Do NOT Add to .mockery.yaml
| Type | Reason | | ---
Установить mockery в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл mockery?
Mock generation workflow for go-crypto-wallet. Activate whenever a developer asks to generate a mock for a new interface, add test coverage that requires a mock, or replace a manually-written test stub for a ports interface. Claude MUST use `make mockery` — never write mock struct code by hand.
Как установить скилл mockery?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл mockery запускает скрипты?
Нет, скилл состоит только из инструкций (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