golang-stretchr-testify

Standardize Go unit tests with stretchr/testify assertions, mocks, and suites.

4|Updated May 17, 2026
One-click install
npx skills add https://github.com/hellopoisonx/aim --skill golang-stretchr-testify-hellopoisonx
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-stretchr-testify
Source: https://github.com/hellopoisonx/aim/tree/main/skills/golang-stretchr-testify
Command: npx skills add https://github.com/hellopoisonx/aim --skill golang-stretchr-testify-hellopoisonx

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps Go developers write maintainable tests by providing consistent, readable assertion patterns, safe precondition handling, and reliable mocking/suite structure using stretchr/testify.

Core Features & Use Cases

  • assert vs require discipline: use require for fail-fast preconditions and assert for continued verifications to avoid nil panics and misleading follow-up errors.
  • Rich assertions for complex checks: equality variants, JSON comparison, async polling via Eventually/EventuallyWithT, and duration/regexp validations.
  • testify/mock correctness: define expectations with mock.Mock, match arguments with built-in and predicate matchers, and verify calls with AssertExpectations(t).
  • testify/suite organization: group related tests with shared setup/teardown while keeping per-test initialization predictable through SetupTest.

Quick Start

Use this skill when your Go codebase already imports github.com/stretchr/testify and you need to write or review tests involving assertions, mocks, suites, or async polling.

Frequently Asked Questions about golang-stretchr-testify

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

FAQPage Schema
When should I use require versus assert in Go tests?

Use `require` for fail-fast preconditions to stop test execution immediately and avoid nil panics, while `assert` allows continued verifications to collect multiple failures within a single test.

How do I check wrapped errors in Go testify assertions?

Use `ErrorIs` for wrapped error checks in testify to correctly verify error chains, ensuring your assertions match the underlying error rather than relying on direct equality comparisons.

What is the best way to test asynchronous code with testify?

Use `EventuallyWithT` for rich async polling assertions in testify, allowing you to evaluate complex conditions over time with proper error reporting instead of manual sleep loops.

How do I verify mock method calls in testify?

Define expectations with `mock.Mock` and verify method calls using `AssertExpectations(t)`, which ensures your mock objects received the expected arguments and were invoked the correct number of times.

Can I group related Go tests with shared setup and teardown?

Use `testify/suite` to group related tests with shared setup and teardown methods, keeping per-test initialization predictable through `SetupTest` while organizing test logic into structured suites.

Why does my testify assertion show misleading follow-up errors after a nil check?

Using `assert` for preconditions instead of `require` allows execution to continue after a failure, causing nil panics and misleading follow-up errors; switch to `require` for guard checks.