writing-go-tests

Installation
SKILL.md

Writing Go Tests

Project-specific test conventions for this codebase.

Critical Rules

  • Always use mockery-generated Moq* mocks when one exists for the interface. Never hand-roll a mock struct for an interface that has a *_mock.go file. Run mockery (no args) from the module root to regenerate mocks after interface changes.
  • Use logger.NoopLogger{} when tests don't need to assert on log output. It already implements the full Logger interface. Never create a custom mock logger just to satisfy the interface — that duplicates NoopLogger for no reason.
  • Use logger.MoqLogger{} only when the test needs to verify specific log calls (e.g., asserting that Warning was called with a specific message).

Mock Selection Guide

Situation Use Import
Interface has a *_mock.go file Moq* struct from that file Same package (in-package tests)
Logger needed but output doesn't matter logger.NoopLogger{} utils/logger
Logger needed and must assert on calls logger.MoqLogger{} utils/logger
Interface has NO mock file (e.g., MultiSelectSelector[T]) Inline mock struct in test file N/A
Related skills

More from mrpointer/dotfiles

Installs
1
GitHub Stars
2
First Seen
Apr 7, 2026