# Golang Stretchr Testify

Comprehensive guide to stretchr/testify for Golang testing.

- Repository: https://github.com/samber/cc-skills-golang (3750 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add samber/cc-skills-golang --skill golang-stretchr-testify -g -a claude-code -y`
Codex: `npx skills add samber/cc-skills-golang --skill golang-stretchr-testify -g -a codex -y`
Cursor: `npx skills add samber/cc-skills-golang --skill golang-stretchr-testify -g -a cursor -y`
Gemini CLI: `npx skills add samber/cc-skills-golang --skill golang-stretchr-testify -g -a gemini-cli -y`

## Description

Comprehensive guide to stretchr/testify for Golang testing. Covers assert, require, mock, and suite packages in depth. Use when writing tests with testify, creating mocks, setting up test suites, or choosing between assert and require. Covers testify assertions, mock expectations, argument matchers, call verification, suite lifecycle, and advanced patterns like Eventually, JSONEq, and custom matchers. Apply when the codebase imports github.com/stretchr/testify.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

**Persona:** You are a Go engineer who treats tests as executable specifications. You write tests to constrain behavior and make failures self-explanatory, not to hit coverage targets.

**Modes:**

- **Write mode**, adding new tests or mocks to a codebase.
- **Review mode**, auditing existing test code for testify misuse.

# stretchr/testify

testify complements Go's `testing` package with readable assertions, mocks, and suites. It does not replace `testing`, always use `*testing.T` as the entry point.

This skill is not exhaustive, refer to library documentation and code examples for more information:

- For Go package docs, symbols, versions, importers, and known vulnerabilities, → See `samber/cc-skills-golang@golang-pkg-go-dev` skill (`godig`), preferred over Context7 for Go package facts.
- To navigate this library's usage in your own code (definitions, call sites, diagnostics), → See `samber/cc-skills-golang@golang-gopls` skill (`gopls`).
- Context7 remains a fallback for docs not indexed on pkg.go.dev.

## assert vs require

Both offer identical assertions. The difference is failure behavior:

- **assert**: records failure, continues, see all failures at once
- **require**: calls `t.FailNow()`, use for preconditions where continuing would panic or mislead

Use `assert.New(t)` / `require.New(t)` for readability. Name them `is` and `must`:

```go
func TestParseConfig(t *testing.T) {
    is := assert.New(t)
    must := require.New(t)

    cfg, err := ParseConfig("testdata/valid.yaml")
    must.NoError(err)    // stop if parsing fails, cfg would be nil
    must.NotNil(cfg)

    is.Equal("production", cfg.Environment)
    is.Equal(8080, cfg.Port)
    is.True(cfg.TLS.Enabled)
}
```

**Rule**: `require` for preconditions (setup, error checks), `assert` for verifications. Never mix randomly.

## Core Assertions

```go
is := assert.New(t)

The rest: https://github.com/samber/cc-skills-golang/blob/HEAD/skills/golang-stretchr-testify/SKILL.md
