golang-stretchr-testifylisted
Install: claude install-skill guynhsichngeodiec/cc-skills-golang
**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. Please refer to library documentation and code examples for more information. Context7 can help as a discoverability platform.
## 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