with one click
unit
Unit tests — hermetic, fast, handler-level tests using generated mocks.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Unit tests — hermetic, fast, handler-level tests using generated mocks.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Visual-design discipline for forge frontends — brief the work before building (never invent an aesthetic without user input), declare the design system before coding, lean on the component library, use restrained color/type systems, never hand-draw complex SVGs, and verify visually before declaring done.
Write Next.js frontends — generated hooks, component library, Tailwind v4, visual verification, and Connect RPC clients.
Outbound boundary translators. One adapter per third-party system / queue / storage backend; narrow interface, vendor-neutral callers.
Write Connect RPC handlers — proto-driven codegen, the thin-translation handler pattern (validate, extract auth, convert proto↔internal, call service, wrap errors via `svcerr.Wrap`), middleware, and testing. Business logic lives in `internal/handlers/<svc>/contract.go`, never in handlers.
Forge project conventions and architecture — project structure, generated vs hand-written code, the generate pipeline, proto annotations, contracts, wiring, and naming.
Use-case orchestrators that compose two or more adapters/services. Deps are interfaces only — designed for unit tests with all-mock collaborators.
| name | unit |
| description | Unit tests — hermetic, fast, handler-level tests using generated mocks. |
Unit tests are hermetic: no network, no database, no filesystem. They test a single handler or function in complete isolation using generated mocks for all contract dependencies.
forge test unit # all unit tests
forge test --service <name> # unit tests for one service
forge test -V # verbose output for debugging
Follow the pattern: TestHandlerName_Scenario_ExpectedOutcome
func TestCreateUser_DuplicateEmail_ReturnsAlreadyExists(t *testing.T) { ... }
func TestGetOrder_NotFound_ReturnsNotFoundError(t *testing.T) { ... }
Use table-driven tests for edge cases — this is idiomatic Go:
tests := []struct {
name string
input *pb.Request
wantErr connect.Code
}{
{"empty name", &pb.Request{Name: ""}, connect.CodeInvalidArgument},
{"valid", &pb.Request{Name: "ok"}, 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { ... })
}
Dependencies are defined as interfaces in your handler contracts. Mock implementations are generated in mock_gen.go files — don't hand-write stubs when the contract mock already exists. Inject them during test setup, never construct real clients.
Mock collaborators, never the subject. Mock the handler's dependencies; the handler itself stays real. A unit test that stubs the thing it claims to test asserts only that your mock returned what you told it to.
For the table-driven scaffolding around these mocks (terse construction, RPC case tables, authed contexts), use the pkg/tdd + pkg/testkit helpers rather than wiring it by hand — see testing/patterns.
Always verify the correct Connect error code is returned, not just that an error occurred:
_, err := handler.CreateUser(ctx, req)
require.Error(t, err)
assert.Equal(t, connect.CodeInvalidArgument, connect.CodeOf(err))
gen/ — it's regenerated and not your logict.Skip() failing tests without linking an issue reference in the skip messageerr != nil when the mock can't fail