golang-stretchr-testify

Explain stretchr/testify assert, require, mocks, and suite patterns for Go tests.

Updated Mar 8, 2026
One-click install
npx skills add https://github.com/tamago0224/kuroshio-mta --skill golang-stretchr-testify-tamago0224
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-stretchr-testify
Source: https://github.com/tamago0224/kuroshio-mta/tree/main/.agents/skills/golang-stretchr-testify
Command: npx skills add https://github.com/tamago0224/kuroshio-mta --skill golang-stretchr-testify-tamago0224

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Comprehensive guide to stretchr/testify for Golang testing. It covers assert, require, mocks, and suites. Use whenever writing tests with testify, creating mocks, setting up test suites, or choosing between assert and require. Trigger on any Go test file importing testify.

Core Features & Use Cases

  • Assert vs Require: explanation of failure behavior and recommended usage.
  • Core Assertions: examples of common checks (Nil, NotNil, Equal, Contains, etc.).
  • Mocks & Suites: guidance on mock usage, mock expectations, and test suites.
  • Common Mistakes: frequent pitfalls and remedies.
  • Advanced Patterns: Eventually, EventualWithT, and suite lifecycles.

Quick Start

Run a small Go test using testify to demonstrate assert vs require, mocks, and a test suite.

Frequently Asked Questions about golang-stretchr-testify

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

FAQPage Schema
What is the difference between assert and require in Go testify?

In Go testify, assert records failures and continues test execution, while require stops execution immediately upon failure. Require is recommended for critical setup checks where continuing would cause panics, and assert is better for collecting multiple failures in one test.

How do I create mock expectations with testify in Go testing?

To create mock expectations with testify, you instantiate a mock struct, call its ExpectMethods to define expected calls and arguments, then assert expectations were met with mock.AssertExpectations. This verifies your code interacted with dependencies correctly during the test.

How do I set up a test suite using testify in Go?

To set up a testify test suite in Go, you embed suite.Suite in your struct, write SetupTest and TearDownTest lifecycle methods, and run the suite with suite.Run. This provides shared setup and teardown across multiple test methods.

Can I use testify for eventual consistency checks in Go tests?

Yes, testify supports eventual consistency checks in Go tests through Eventually and EventualWithT. These functions repeatedly evaluate a condition over a time duration, making them suitable for testing asynchronous operations or state changes that settle over time.

What are common mistakes when writing Go tests with testify?

Common mistakes when writing Go tests with testify include using require where assert is better suited, failing to call mock.AssertExpectations to verify calls, and improper suite lifecycle management. Remedies include choosing assert to collect failures and ensuring setup logic uses require.

Do I need any external dependencies to use testify mocks and suites in Go?

You need to import the stretchr/testify package in your Go project to use its mocks and suites. The package provides the mock and suite sub-packages required to define mock expectations and structure test suites without additional external dependencies.