Skip to content
Back to skills

Golang Testing

ASecurity

Write unit tests with table-driven patterns and interface mocking in Go. Use when writing Go unit tests, table-driven tests, or using mock interfaces.

  • 24 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 4, 2026
testinggotesting

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned September 4, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill golang-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Golang Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Golang Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-golang-testing/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-golang-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: golang-testing
description: Write unit tests with table-driven patterns and interface mocking in Go. Use when writing Go unit tests, table-driven tests, or using mock interfaces.
metadata:
  triggers:
    files:
    - '**/*_test.go'
    keywords:
    - testing
    - unit tests
    - go test
    - mocking
    - testify
---
# Golang Testing

## **Priority: P0 (CRITICAL)**

## Implementation Workflow

1. **Write failing test first** — Follow Red-Green-Refactor TDD workflow.
2. **Use table-driven tests** — Define test cases as slice of structs; iterate with `t.Run()`.
3. **Zero Volatile Fields for Struct Comparison** — When asserting struct equality, zero out timestamps, dynamic IDs, or generated tokens before `assert.Equal` to prevent flaky assertions.
4. **Mock via interfaces** — Use DI and interfaces. Prefer `mockery` for auto-generated mocks or manual mocks for simple cases.
5. **Run parallel** — Use `t.Parallel()` for non-sequential tests to speed up CI.
6. **Clean up resources** — Use `t.Cleanup()` to restore state or release DB/file resources.
7. **Check coverage** — Aim for >80% line coverage. Run `go test -cover` to audit.

See [table-driven test examples](references/table-driven-tests.md)

## Tools

- **Stdlib**: `testing` package usually enough.
- **Testify**: Assertions (`assert`, `require`) and mocks.
- **Mockery**: Auto-generate mocks for interfaces.
- **GoMock**: Popular mocking framework alternative.

## Naming

- Test file: `*_test.go`
- Test function: `func TestName(t *testing.T)`
- Example function: `func ExampleName()`

## Anti-Patterns

- **No assert in loops**: use `t.Run` subtests to isolate failures.
- **No brittle assertions on volatile fields**: avoid matching exact timestamps or non-deterministic IDs without normalization.
- **No global mock state**: define mocks locally within test scope.
- **No skipping race detection**: always run `go test -race` in CI.

## References

- [Table-Driven Tests](references/table-driven-tests.md)
- [Mocking Strategies](references/mocking-strategies.md)

Files in this skill

  • SKILL.md2 KB
  • evals/evals.json1.9 KB
  • references/mocking-strategies.md854 B
  • references/table-driven-tests.md1.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in testing →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.