.agents/skills/tdd-unit-testing/SKILL.md
Write unit tests in Go following Red-Green-Refactor TDD principles.
npx skillsauth add gobetterauth/go-better-auth tdd-unit-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
tt patterns for multiple casesTestTodoService_CreateTodo_ReturnsID_OnSuccessnew() function in Go 1.26+ to initialise reference type values instead of creating pointer functions that return a reference type. For example, use new("user-1") instead of a function such as ptrString("user-1") that returns *string to create a pointer to a string value.Handlers: Create handler struct with UseCase field; return http.HandlerFunc from Handler() method; test via httptest
Services: Mock repositories; test business logic and error handling
Repositories: Test against real SQLite database (Bun ORM); use test fixtures to set up schema
Integration tests: Use fixtures; test plugin routes end-to-end
Every test follows Arrange-Act-Assert (AAA):
See examples/ for Todos testing patterns:
test_helpers.go - MockTodoUseCase and MockTodoService interfaceshandler_test.go - Handler struct with UseCase, Handler() method, httptest patternsrepository_test.go - Real SQLite database tests with test fixtures, CRUD operationstodo_service_test.go - Service tests with mocked repositories and table-driven testsplugin_integration_test.go - End-to-end route testing with fixturesAssertExpectations(t)go test ./... # Run all tests
go test -cover ./... # With coverage
go test -run TestFunc ... # Specific test
go test -race ./... # Detect race conditions
tools
Orchestrate services and repositories through use cases to implement application-level workflows and business scenarios.
tools
Define and implement services that encapsulate business logic with proper constructor-based dependency injection.
tools
Register and retrieve services at runtime using a thread-safe service registry pattern for loose coupling between plugins.
data-ai
Implement repository interfaces for data persistence and abstraction over database operations using Bun ORM.