testify-tdd_skill
- Go
3
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill linehaul-ai/linehaulai-claude-marketplace --skill testify-tdd- SKILL.md12.6 KB
Overview
This skill teaches writing Go tests with stretchr/testify and applying Test-Driven Development (TDD) workflows. It focuses on assert vs require patterns, interface mocking with testify/mock, table-driven tests, and organizing suites with testify/suite. Use it to build reliable unit tests, create clean mocks, and follow the red-green-refactor cycle.
How this skill works
The skill inspects common testing patterns and provides concrete examples you can copy into Go test files. It explains when to use require (stop on failure) versus assert (continue on failure), shows how to define and use mocks, and demonstrates table-driven tests and test suites. It also outlines a practical TDD loop: write a failing test, implement minimal code to pass, then refactor and expand test coverage.
When to use it
- Writing unit tests that interact with external dependencies and need isolation
- Implementing TDD workflows for new features or bug fixes
- Creating mocks for interfaces to assert calls and return values
- Organizing related tests with setup/teardown using test suites
- Building table-driven tests to cover multiple scenarios concisely
Best practices
- Use require for test prerequisites and assert for multiple independent verifications
- Mock only at interface boundaries and avoid mocking what you don’t own
- Prefer table-driven tests for repetitive scenario coverage to reduce duplication
- Keep tests independent with no shared mutable state between tests
- Name tests descriptively and follow Arrange-Act-Assert structure
- Verify mock expectations (AssertExpectations) and use matchers for flexible argument checks
Example use cases
- TDD for a shipping calculator: write failing tests, implement minimal logic, then refactor safely
- Unit testing a service with a UserRepository mock to verify Save and GetByID interactions
- Converting repeated tests into a table-driven TestCalculateDiscount covering success and error cases
- Grouping related service tests in a testify suite with shared setup and teardown
- Using mock.Run to modify arguments (e.g., set generated IDs) and AssertNumberOfCalls to verify call counts
FAQ
Use require for setup steps or any condition that makes further checks meaningless if it fails; use assert for multiple independent verifications so all failures are reported.
How do I mock return values that change across calls?
Chain On(...) calls with .Once() or use Run to programmatically modify arguments and return values; testify/mock supports successive Return/Once sequences.
Should I test private functions or only public behavior?
Prefer testing public behavior. Use same-package tests when you need access to unexported helpers, but avoid coupling tests to implementation details.