go-stretchr-testify

Write and review Go tests and mocks using the stretchr/testify assertion library.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill go-stretchr-testify-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-stretchr-testify
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/go/go-stretchr-testify
Command: npx skills add https://github.com/asarchami/dotfiles --skill go-stretchr-testify-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing Go tests with testify often leads to subtle mistakes: swapped expected/actual arguments, assert used where require is needed, unverified mocks, and error comparisons that fail silently on wrapped errors. This Skill provides disciplined guidance for using testify correctly across assertions, mocks, and suites. ## Core Features & Use Cases - Assertion discipline: Rules for choosing assert vs require, correct (expected, actual) argument order, and chain-walking error checks with ErrorIs/ErrorAs. - Mock authoring and verification: Patterns for embedding mock.Mock, argument matchers (Anything, AnythingOfType, MatchedBy), call modifiers (Once, Times, Maybe), and mandatory AssertExpectations verification. - Suite lifecycle management: Setup/TearDown hooks, the required suite.Run launcher, and mixing failure modes via s.Require(). - Use Case: While writing a test for an order service, use this Skill to set up a MockSender with typed argument matchers, poll async state with EventuallyWithT, and audit the test file for assert-as-guard mistakes before committing. ## Quick Start Ask the assistant to write a testify-based test with a mock for your Go interface, or to review an existing testify test file for misuse.

Frequently Asked Questions about go-stretchr-testify

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between assert and require in testify?

Use require for preconditions where continuing would panic or mislead, such as setup and error checks, since it calls t.FailNow. Use assert for verifications so all failures are reported at once. Never mix them randomly within a test.

How do I mock an interface with testify mock?

Embed mock.Mock in a struct, implement each interface method by forwarding through m.Called(), and declare expectations with On(...) plus argument matchers like mock.Anything or mock.MatchedBy. Always call AssertExpectations(t) at the end so unmet expectations fail the test.

Why does testify Equal fail on wrapped errors?

Equal compares error values directly, so a wrapped error never matches its sentinel. Use ErrorIs(err, sentinel) or ErrorAs(err, &target) to walk the error chain, and ErrorContains for message text checks.

Why does my testify suite run zero tests?

A suite without a launcher function executes nothing silently. Add func TestMySuite(t *testing.T) { suite.Run(t, new(MySuite)) } so go test discovers and runs the suite's tests.

How do I test asynchronous code with testify?

Use Eventually or EventuallyWithT with an explicit timeout and tick interval to poll async state instead of Sleep plus a one-shot assert. EventuallyWithT accepts a CollectT for rich assertions inside the poll.