Skillshub golang-testing
Standards for unit testing, table-driven tests, and mocking in Golang. Use when writing Go unit tests, table-driven tests, or using mock interfaces. (triggers: **/*_test.go, testing, unit tests, go test, mocking, testify)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/golang-testing" ~/.claude/skills/comeonoliver-skillshub-golang-testing-6a2dd8 && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/golang-testing/SKILL.mdsource content
Golang Testing Standards
Priority: P0 (CRITICAL)
Guidelines
TDD & Table-Driven Tests
- Pattern: Use
for multi-input scenarios. UseTable-Driven Tests
for each test case.t.Run() - Workflow: Follow Red-Green-Refactor. Write a failing test case before implementing logic.
- Mocking: Use
andInterfaces
. Avoid complex mocking frameworks; preferDependency Injection
ormanual mocks
.GoMock - Coverage: Aim for
line coverage. Run> 80%
to audit.go test -cover - Assertions: Use
ortestify/assert
for readable checks:testify/require
.assert.NoError(t, err) - Parallelism: Use
for non-sequential tests to speed up CI.t.Parallel() - Cleanup: Use
to reset state or release resources (DB/Files).t.Cleanup() - Subtests: Name each subtest case clearly (
,"Valid input"
,"Missing ID"
)."Network timeout"
Golden Snippet
See Table-Driven Tests for full template.
Tools
- Stdlib:
package is usually enough.testing - Testify (
): Assertions (stretchr/testify
,assert
) and Mocks.require - Mockery: Auto-generate mocks for interfaces.
- GoMock: Another popular mocking framework.
Naming
- Test file:
*_test.go - Test function:
func TestName(t *testing.T) - Example function:
func ExampleName()
Anti-Patterns
- No Manual Mocks: Use
for boilerplate-heavy mocks.mockery - No Assert in Loop: Use
to isolate failures within table-driven loops.t.Run - No Global Mocks: Define mocks locally or within test scope to avoid state leakage.