golang-stretchr-testify

Guide Go unit tests using stretchr/testify assertions, mocks, and suites.

Updated Apr 17, 2026
One-click install
npx skills add https://github.com/Manu343726/audible-exporter --skill golang-stretchr-testify-manu343726
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-stretchr-testify
Source: https://github.com/Manu343726/audible-exporter/tree/main/.agents/skills/golang-stretchr-testify
Command: npx skills add https://github.com/Manu343726/audible-exporter --skill golang-stretchr-testify-manu343726

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps Go engineers write reliable, readable unit tests using stretchr/testify by standardizing assertion behavior, mock verification, and suite lifecycle patterns.

Core Features & Use Cases

  • assert vs require guidance: Use require for preconditions to stop early and assert for verifications so failures are aggregated.
  • High-signal assertions: Prefer correct equality semantics, richer matchers (JSONEq, Regexp, ElementsMatch), and correct argument ordering for better diffs.
  • testify/mock correctness: Set expectations with argument matchers and always verify with AssertExpectations to avoid silent false positives.
  • testify/suite structure: Organize related tests with shared setup/teardown and per-test initialization using SetupTest.
  • Async test polling: Use EventuallyWithT with CollectT to make multiple assertions during polling without losing error context.

Quick Start

Use the golang-stretchr-testify skill to generate a Go test plan that uses assert.New for verifications, require.New for guard checks, and testify/mock with proper AssertExpectations, tailored to how the codebase imports github.com/stretchr/testify.

Frequently Asked Questions about golang-stretchr-testify

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

FAQPage Schema
How do I write better Go tests with testify assertions and avoid confusing failure output?

To write better Go tests with testify, use correct argument ordering—passing (expected, actual)—and prefer rich matchers like JSONEq or ElementsMatch to generate high-signal diffs that make test failures easy to diagnose.

When should I use require vs assert in Go test suites?

Use require for test preconditions to stop execution immediately if a setup fails, and use assert for test verifications so multiple assertion failures are aggregated and reported together in your Go test suites.

How do I create mocks in Go using testify/mock and prevent silent false positives?

Create mocks in Go by setting expectations with argument matchers and call modifiers, then always call AssertExpectations on your mock to verify all expected calls were made, preventing silent false positives.

How do I organize Go unit tests with shared setup and teardown using testify/suite?

Organize Go unit tests using testify/suite to group related tests, leveraging SetupTest for per-test initialization and shared setup and teardown methods to manage common test lifecycle state cleanly.

Can I handle async polling in Go tests without losing error context?

Handle async polling in Go tests using EventuallyWithT combined with CollectT, allowing you to make multiple assertions during polling without losing error context when the async condition fails.

What are the limitations of using testify for Go testing?

When using testify for Go testing, you must pass *testing.T as the entry point and ensure proper mock verification; failing to use AssertExpectations or misusing require for verifications limits failure visibility.