# Testing Go Code

> Run Go unit tests, coverage reports, and benchmarks. Use when you need to run tests, check coverage, run benchmarks, or regenerate mocks after interface changes.

- Skill: `majiayu000/testing-go-code` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add majiayu000/testing-go-code`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/testing-go-code/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/testing-go-code

---


# Testing Go Code

All commands run from the Go module root (`installer/`).

## Unit Tests

```bash
task test                       # Run all tests with race detection
task test -- -run TestName      # Run specific test(s)
task test -- -short             # Skip integration tests
```

For test conventions (naming, assertions, table-driven patterns, mock usage), see the `writing-go-tests` skill.

## Coverage

```bash
task cov
```

Runs tests with coverage and opens an HTML report in the browser.

## Benchmarks

```bash
task bench
```

Runs all benchmarks with memory allocation stats.

## Combined Check

```bash
task check
```

Runs tests + lint in sequence. Use before committing.

## Mock Regeneration

```bash
mockery
```

Run from the module root with no arguments after adding or modifying interfaces. Configuration is in `.mockery.yml`. Never edit generated mock files (`*_mock.go`) manually.

