test-usecase

Writes Go usecase tests against real PostgreSQL, repositories, and transactions using five wiring viewpoints.

Updated Sep 14, 2026
One-click install
npx skills add https://github.com/nakamori-naoya/go-convention-plugins --skill test-usecase-nakamori-naoya
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: test-usecase
Source: https://github.com/nakamori-naoya/go-convention-plugins/tree/main/plugins/go-convention/skills/test-usecase
Command: npx skills add https://github.com/nakamori-naoya/go-convention-plugins --skill test-usecase-nakamori-naoya

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing usecase tests in Go often leads to bloated suites that re-verify domain rules, SQL correctness, or handler concerns, or to mock-heavy interaction tests that only count calls. This Skill defines exactly what a usecase test should verify: the five wiring viewpoints (input resolution, multi-aggregate coordination, source selection, transaction boundaries, command dispatch and persistence), checked against real infrastructure. ## Core Features & Use Cases - Five-viewpoint case design: Classifies each line of a usecase's Execute method into input resolution, aggregate coordination, source selection, transaction boundary, or command dispatch, and writes one test case per distinct wiring branch. - Real infrastructure testing: Runs tests against a dockertest PostgreSQL instance with real repositories, real tx.Manager, and real query services, replacing only the IDGenerator with a deterministic fixed implementation. - Table-driven structure: Enforces a seed{Table} → ids → in → want/wantErr/want{Table} field order with rdbtest helpers for seeding and reading rows, keeping raw SQL and aggregate assembly out of test bodies. - Use Case: Given a ConfirmReservation usecase, produce four test cases covering empty-ID rejection, successful confirmation with event persistence, idempotent re-confirmation rejection, and rollback on mid-save constraint failure. ## Quick Start Ask the AI to write tests for this usecase following the test-usecase convention, pointing it at the usecase implementation and the rdbtest persistence test helpers.

Frequently Asked Questions about test-usecase

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test a Go usecase layer without mocks?▼

Run the usecase's Execute against a real PostgreSQL instance started by dockertest, with real repositories, a real transaction manager, and real query services. Seed prerequisite rows with table-level helpers and assert on database state and return values instead of call counts.

What should usecase tests cover in a DDD Go project?▼

Usecase tests should cover five wiring viewpoints: input resolution to value objects, coordination across multiple aggregates, read-source selection, transaction commit and rollback boundaries, and command dispatch with persistence. Business rules, SQL correctness, and proto conversion belong to other layers.

How do I test transaction rollback in Go without mocking failures?▼

Trigger rollback with a real database constraint violation, such as pre-seeding a conflicting unique key so a mid-transaction INSERT fails. Then assert the returned sentinel error and that all earlier writes in the transaction were rolled back.

Can I use t.Parallel with dockertest PostgreSQL tests?▼

No. When one real database is shared per test package via TestMain, tests must run serially without t.Parallel, and each case resets all tables before seeding its own fixture rows to stay isolated.

When should usecase tests not be written?▼

Skip cases that only vary input values along the same result path, since those belong to domain-layer boundary tests. Also stop when the usecase contains business decisions, calls time.Now directly, or lacks the rdbtest helpers needed for seeding.