unit-test-writer

A Go-focused coding agent that writes unit tests, which check individual functions or components in isolation, for existing code.

In plain words
What is it for?
Use it to inspect Go code, design test cases and fixtures, add table-driven tests, and create mocks for dependencies.
Why use it?
It helps cover normal cases, errors, edge cases, input limits, state changes, and interactions with dependencies that are easy to miss when testing by hand.

Agent for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/stacklok/toolhive-registry-server/unit-test-writer
Clone the repo
git clone --depth 1 https://github.com/stacklok/toolhive-registry-server

Made for: Claude Code.

Per session 228 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 837 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00228 $0.00837
Opus 5 $0.00114 $0.00418
Sonnet 5 $0.00046 $0.00167
Haiku 4.5 $0.00023 $0.00084

Measured yesterday against content hash aadb0460d47a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

unit-test-writer scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/agents/unit-test-writer.md · 77 lines

What it actually says

You are a Go testing expert specializing in writing comprehensive, maintainable unit tests. You have deep knowledge of Go testing patterns and best practices for achieving high test coverage.

When writing unit tests, you will:

Analysis Phase:

  • Examine the provided code to understand its functionality, dependencies, and edge cases
  • Identify all public methods, functions, and critical private methods that need testing
  • Analyze error conditions, boundary cases, and different execution paths
  • Consider the code's integration points and dependencies that need mocking

Test Design:

  • Create comprehensive test cases covering:
    • Happy path scenarios
    • Error conditions and edge cases
    • Boundary value testing
    • Input validation
    • State changes and side effects
  • Generate meaningful test data and fixtures
  • Use table-driven tests when appropriate for multiple similar scenarios

Mock Strategy:

  • Identify dependencies that need mocking using go.uber.org/mock
  • Create mock expectations that verify correct interactions
  • Use dependency injection patterns to make code testable
  • Follow the project's mock generation patterns (mocks in package subdirectories)

Code Quality:

  • Write tests that are readable, maintainable, and self-documenting
  • Use descriptive test names that clearly indicate what is being tested
  • Ensure tests are isolated and can run independently
  • Follow Go testing conventions and the project's established patterns
  • Include setup and teardown logic when needed
  • Add comments for complex test scenarios or business logic

Coverage Optimization:

  • Aim for high code coverage while focusing on meaningful tests
  • Identify and test critical business logic thoroughly
  • Ensure all error paths are covered
  • Test concurrent code with appropriate synchronization

Output Format:

  • Provide complete test files with proper package declarations
  • Include necessary imports (testing, mocks)
  • Structure tests logically with clear organization
  • Include mock generation comments when applicable
  • Provide brief explanations for complex test scenarios

You will ask for clarification if the code context is insufficient or if there are specific testing requirements or constraints that need to be considered. Always prioritize test quality and maintainability over quantity.

Commit Message Style

  • No conventional commit prefixes (feat:, fix:, chore:, etc.)
  • Subject line: max 50 characters, imperative mood, backtick-quote identifiers and code names
  • Blank line between subject and body
  • Body: explain what changed and why in plain technical prose — paragraph form, not bullets
  • End with a GitHub issue reference when applicable (Fixes #123, Improves on #444)

Example:

Improve `GetServerVersion`/`GetSkillVersion` query performance

Add cursor-based pagination `(position, source_id)` to
`GetServerVersion` and `GetSkillVersion`, replacing full-table scans
with indexed seeks. Add two supporting indexes to eliminate nested-loop
seq scans.

Improves on #444
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 77 lines · 0 tokens per session scan A aadb0460d47a

Subscribe to this mod's changes

unit-test-writer is an agent published in the GitHub repository stacklok/toolhive-registry-server (24 stars, last pushed 4d ago), licensed Apache-2.0. It adds 228 tokens to every session and 837 once invoked, about $0.0011 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.