MCPInstall

writing-go-tests

Applies current Go testing best practices. Use when writing or modifying Go test files or advising on Go testing strategies.

Installs
79
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/sammcj/agentic-coding --skill writing-go-tests
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads writing-go-tests automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Go Testing Best Practices

This skill provides actionable testing guidelines. For detailed implementation patterns, code examples, rationale, and production system references, consult go-testing-best-practices.md.

When Working with Go Tests

Always apply these current best practices:

1. Test Organisation

  • Place test files alongside source code using *_test.go naming
  • Use internal tests (same package) for unit testing unexported functions
  • Use external tests (package foo_test) for integration testing and examples
  • Split test files by functionality when they exceed 500-800 lines (e.g., handler_auth_test.go, handler_validation_test.go)

2. Table-Driven Testing

  • Prefer map-based tables over slice-based for automatic unique test names
  • Use descriptive test case names that appear in failure output
  • See detailed guide for complete pattern and examples

3. Concurrent Testing

  • Use testing/synctest for deterministic concurrent testing (Go 1.24+)
  • This eliminates flaky time-based tests and runs in microseconds instead of seconds
  • For traditional parallel tests, always call t.Parallel() first in test functions

4. Assertions and Comparisons

  • Use cmp.Diff() from google/go-cmp for complex comparisons
  • Standard library is sufficient for simple tests
  • Testify is the dominant third-party framework when richer assertions are needed

5. Mocking and Test Doubles

  • Favour integration testing with real dependencies over heavy mocking
  • Use Testcontainers for database/service integration tests
  • When mocking is necessary, prefer simple function-based test doubles over code generation
  • Use interface-based design ("accept interfaces, return structs")

6. Coverage Targets

  • Aim for 70-80% coverage as a practical target
  • Focus on meaningful tests over percentage metrics
  • Use go test -cover and go tool cover -html for analysis

7. Test Fixtures

  • Use testdata directory for test fixtures (automatically ignored by Go toolchain)
  • Implement golden file testing for validating complex output
  • Use functional builder patterns for complex test data

8. Helpers and Cleanup

  • Always mark helper functions with t.Helper() for accurate error reporting
  • Use t.Cleanup() for resource cleanup (superior to defer in tests)

9. Benchmarking (Go 1.24+)

  • Use B.Loop() method as the preferred pattern (prevents compiler optimisations)
  • Combine with benchstat for statistical analysis
  • Use -benchmem for memory profiling

10. Naming Conventions

  • Test functions: Test*, Benchmark*, Fuzz*, Example* (capital letter after prefix)
  • Use got and want for actual vs expected values
  • Use descriptive test case names in table-driven tests

Integration vs Unit Testing

  • Separate tests by environment variable (preferred over build tags)
  • See detailed guide for implementation pattern

Additional Reference Material

Load go-testing-best-practices.md when you need:

  • Complete code examples for table-driven tests, mocking patterns, golden files, helpers, or benchmarks
  • Detailed explanation of testing/synctest concurrent testing patterns
  • Rationale behind why specific patterns are preferred over alternatives
  • Production system examples and statistics (Kubernetes, Docker, Uber, Netflix, ByteDance)
  • Context on testing framework choices (Testify, GoMock, Testcontainers)
  • Comprehensive coverage strategies and tooling details
  • Integration testing patterns with containerisation

The detailed guide contains full context, examples with explanations, and production-proven patterns. This SKILL.md provides the actionable rules to apply.

Key Principle

Focus on meaningful tests that validate behaviour rather than implementation. Pragmatic excellence over theoretical perfection.

FAQ

What does the writing-go-tests skill do?

Applies current Go testing best practices. Use when writing or modifying Go test files or advising on Go testing strategies.

How do I install writing-go-tests?

Run npx skills add https://github.com/sammcj/agentic-coding --skill writing-go-tests in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/writing-go-tests/ (personal) or .claude/skills/writing-go-tests/ (project).

Which AI agents can use writing-go-tests?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is writing-go-tests safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains writing-go-tests?

It is published by sammcj in sammcj/agentic-coding. It has 79 recorded installs.

More from sammcj/agentic-coding

View all →

Critically analyse the reasoning in written content (articles, blogs, transcripts, reports), not code. Use only when explicitly asked to critically analyse or critique an argument.

AI & Agents2.4K installs

Applies the Diataxis framework to create or improve technical documentation. Use when being asked to write high quality tutorials, how-to guides, reference docs, or explanations, when reviewing documentation quality, or when deciding what type of documentation to create. Helps identify documentation types using the action/cognition and acquisition/application dimensions.

Docs & Writing615 installs

creating-development-plans

sammcj/agentic-coding

Creates structured development plans with phased task breakdowns, requirements, and QA checklists. Use when the user explicitly asks to create a dev plan, development plan, or document development requirements.

ghostty-config

sammcj/agentic-coding

Use when creating, editing or debugging Ghostty terminal configuration - config.ghostty files, config option names and their valid values, keybinds and key sequences, themes, fonts, shell integration, or ghostty + CLI actions. Covers macOS and Linux/GTK differences.

AI & Agents221 installs

code-simplification

sammcj/agentic-coding

Use this skill when you need to review and refactor code to make it simpler, more maintainable, and easier to understand. Helps with identifying overly complex solutions, unnecessary abstractions.

prompt-enhancer

sammcj/agentic-coding

Transform poor or overly simple prompts with expert-level framing. Use when the user explicitly asks to improve, refine, or rewrite a prompt, or wants help framing a request for another AI system. Do NOT use for authoring, reviewing, or migrating system prompts or skills targeting a specific Claude model.

AI & Agents184 installs

Popular testing & qa skills

View category →

tdd

mattpocock/skills

Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.

Testing & QA1.2M installs

grilling

mattpocock/skills

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.

Testing & QA996.2K installs

migrate-to-shoehorn

mattpocock/skills

Migrate test files from as type assertions to @total-typescript/shoehorn. Use when user mentions shoehorn, wants to replace as in tests, or needs partial test data.

Testing & QA484.1K installs

run-train

lllllllama/rigorpilot-skills

Rigor Train skill for deep learning research repositories. Use when a documented or selected training command should be run conservatively for startup verification, short-run verification, full kickoff, or resume, with command, config, seed, log, checkpoint, status, and metric evidence written to standardized trainoutputs/. Do not use for environment setup, exploratory sweeps, speculative idea implementation, or end-to-end orchestration.

Testing & QA337.8K installs

test-driven-development

obra/superpowers

Use when implementing any feature or bugfix, before writing implementation code

Testing & QA261.8K installs

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

Testing & QA216.8K installs