본문으로 건너뛰기
cccskills
무료GitHub에 공개

tdd-unit-testing

Write unit tests in Go following Red-Green-Refactor TDD principles.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

Authula/authula스타 273(GitHub 273 + cccskills 0)

실행 점수 미검증

설치 방법 보기

포함된 파일(6)

  • SKILL.md3.7 KB
  • examples/handler_test.go3.2 KB
  • examples/plugin_integration_test.go6.4 KB
  • examples/repository_test.go4.9 KB
  • examples/test_helpers.go1.8 KB
  • examples/todo_service_test.go2.5 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

TDD & Unit Testing

When to use this skill

  • Implement new features (write test first)
  • Add test coverage for code changes
  • Test business logic such as handlers, services, and repositories.
  • Ensure error paths and edge cases are covered

Key principles

  1. Red-Green-Refactor: Write failing test → implement → refactor
  2. Mock dependencies: Use testify/mock to isolate units and put all mocks in a separate mocks.go file under a tests folder within the package being tested
  3. Table-driven tests: Use tt patterns for multiple cases, keep tests focused and small with one behavior per test case and test success and error paths.
  4. Descriptive names: TestTodoService_CreateTodo and all the scenarios and logic should be tested as individual test cases using the table driven approach
  5. Temporary variables: Utilise the new() 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. This also includes all other reference types such as new(10) for *int, new(true) for *bool, etc.
  6. Assert mock expectations: Always call AssertExpectations(t) at the end of tests that use mocks to ensure all expected calls were made.
  7. Helpers and test harnesses: Always utilise any test helpers and utils from the internals folder as it contains helpers and utils for tests. If a helper function or util is needed then see whether it is something that is global and can be used across the codebase but if it is specific to a plugin, then keep it local to the plugin by putting the helpers and utils within the plugin's tests folder. Never write test code differently in each handler, service, or repository test file. Always follow the same patterns and principles to ensure consistency and maintainability across all tests.

Testing strategy

Handlers: Create handler struct with UseCase/Service 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

Pattern

Every test follows Arrange-Act-Assert (AAA):

  1. Arrange: Create mocks, set expectations, prepare test data
  2. Act: Call the function under test
  3. Assert: Verify results and confirm all mock expectations were met

Example files

See examples/ for Todos testing patterns:

  • test_helpers.go - MockTodoUseCase and MockTodoService interfaces
  • handler_test.go - Handler struct with UseCase, Handler() method, httptest patterns
  • repository_test.go - Real SQLite database tests with test fixtures, CRUD operations
  • todo_service_test.go - Service tests with mocked repositories and table-driven tests
  • plugin_integration_test.go - End-to-end route testing with fixtures

Common mistakes

  1. Not writing test first (Red-Green-Refactor discipline)
  2. Testing multiple behaviors in one test
  3. Using real database instead of mocks
  4. Skipping error cases and edge cases
  5. Not asserting mock expectations with AssertExpectations(t)
  6. Tests that break on harmless refactoring

Quick commands

make test                  # Run all tests
make coverage              # With coverage
go test -run TestFunc ...  # Specific test
go test -race ./...        # Detect race conditions

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Wire dependencies using constructor-based dependency injection throughout services, repositories, and handlers.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

Authula/authula2732026년 10월 24일 업데이트

Use this skill when answering questions, explaining concepts, writing technical responses, reviewing code, or helping with development tasks. Communicate in clear, simple, standard English. Keep answers concise and focused, remove unnecessary filler and repetition, explain technical ideas in plain language, and structure information so it is easy to read and understand. When showing code, present it clearly with enough context for the developer to understand what it does and where it belongs.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

Authula/authula2732026년 10월 24일 업데이트

grill-me

무료

A relentless interview to sharpen a plan or design.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

Authula/authula2732026년 10월 24일 업데이트

grilling

무료

Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

Authula/authula2732026년 10월 24일 업데이트

Implement HTTP handlers that parse requests, invoke use cases, and format responses following REST conventions.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

Authula/authula2732026년 10월 24일 업데이트

handoff

무료

Compact the current conversation into a handoff document for another agent to pick up.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

Authula/authula2732026년 10월 24일 업데이트

Authula의 스킬 모두 보기

이 스킬의 문제 신고