> 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)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/golang-testing?format=md"Golang Testing Standards
Priority: P0 (CRITICAL)
Principles
Guidelines
TDD Workflow
- Red: Write a failing table-driven test case.
- Green: Implement logic to pass.
- Refactor: Simplify code.
Verification Checklist (Mandatory)
- Table-Driven: Are multiple scenarios handled in a single test function via tables?
- Coverage: Does the test cover edge cases (nil, error, empty)?
- No Side Effects: Are global states reset or avoided?
- Error Checking: Are errors asserted for both existence (
assert.Error) and content? - Subtests: Are subtests named descriptively?
Golden Snippet
See Table-Driven Tests for full template.
Tools
- Stdlib:
testingpackage is usually enough. - Testify (
stretchr/testify): Assertions (assert,require) and Mocks. - 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
mockeryfor boilerplate-heavy mocks. - No Assert in Loop: Use
t.Runto isolate failures within table-driven loops. - No Global Mocks: Define mocks locally or within test scope to avoid state leakage.
References
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)