golang-stretchr-testify

Implement stretchr/testify assertions, mocks, and suites in Go tests.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It helps you write reliable, readable Go tests by showing the correct way to use stretchr/testify for assertions, fail-fast checks, mocking, and suites.

Core Features & Use Cases

  • assert vs require discipline: Use assert for non-critical verifications and require for preconditions to avoid nil-panics and misleading failures.
  • Advanced assertions: Cover equality, error-chain checks (ErrorIs/ErrorAs), JSONEq, Eventually polling (including EventuallyWithT), and more.
  • testify/mock and suite patterns: Build mocks with expectations, match arguments with mock.Anything / mock.AnythingOfType / mock.MatchedBy, verify with AssertExpectations, and structure tests with suite.Suite lifecycles.

Use case example: You are writing a Go handler test that needs to (1) stop immediately when input parsing fails, (2) verify structured JSON output ignoring key order, and (3) mock a dependency where the same method is called with retry/failure sequences.

Quick Start

Use this skill when your codebase imports github.com/stretchr/testify and you want to apply correct patterns for assertions, mocks, and suite lifecycle.

Frequently Asked Questions about golang-stretchr-testify

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

FAQPage Schema
How do I use testify assertions in Go without causing nil-panics in my tests?

Use testify's require package for preconditions to stop test execution immediately on failure, preventing nil-panics, and use assert for non-critical verifications that allow subsequent checks to run.

How do I mock dependencies in Go testing using testify/mock?

Build mocks with testify/mock by setting expectations, matching arguments with mock.MatchedBy or mock.Anything, and verifying calls with AssertExpectations to ensure isolated dependency behavior in Go tests.

Can I verify error chains and structured JSON output with testify assertions?

Yes, testify assertions support error-chain verification with ErrorIs and ErrorAs, structured JSON comparison ignoring key order with JSONEq, and expressive equality checks for Go test validation.

What is the best way to test asynchronous operations in Go with testify?

Use testify's Eventually and EventuallyWithT polling assertions to test asynchronous operations, allowing you to poll for expected state changes over time with expressive fail-fast checks in Go.

How do I structure Go test suites using testify?

Structure Go tests with testify's suite.Suite to leverage lifecycle hooks, organizing setup and teardown operations while running grouped test methods through the suite launcher for dependable integration tests.

Why does my Go test keep failing silently when parsing input fails?

Your test likely uses assert instead of require for preconditions; switching to require stops execution immediately upon input parsing failure, avoiding misleading downstream failures in your Go tests.