Skip to content

[go-fan] Go Module Review: stretchr/testify #11541

Description

@github-actions

🐹 Go Fan Report: stretchr/testify

Module Overview

testify is the de-facto standard assertion/mocking toolkit for Go, providing assert/require packages plus mock and suite packages that layer nicely on top of the standard testing package.

Current Usage in gh-aw-mcpg

This project uses testify extensively — it is our most heavily used direct dependency.

  • Files: 303 files import stretchr/testify
  • Import Count: 295 testify/assert imports, 275 testify/require imports
  • Key APIs Used (top usages): assert.Equal (3061), require.NoError (2460), assert.Contains (1160), require.NotNil (920), require.Error (687), assert.True (684), assert.ErrorContains (546), require.True (498), assert.Nil (430), assert.False (418), assert.Empty (355), assert.Len (199), assert.ElementsMatch (71), assert.NotPanics (62), assert.ErrorIs (31)
  • The AGENTS.md project convention already codifies testify best practices (assert vs require, bound asserters, specific assertions over generic ones), and a spot-check found no anti-patterns: no assert.True(t, len(x)==0), no assert.Nil(t, err) for real errors, no assert.Equal(t, true, ...) style calls. Usage is already idiomatic.
  • testify/suite and testify/mock are not used at all in this codebase — all mocking is done manually (per AGENTS.md: "Mock external dependencies (Docker, network)").

Research Findings

Currently pinned: v1.11.1 (Aug 2025). Latest available: v1.12.1 (2026-08-19), with v1.12.0 released 2026-08-17.

Recent Updates

  • v1.12.0: assert.PanicsWithError now reports the actual error message on failure; assert.IsIncreasing/IsDecreasing family can return a bool without failing the test; very long objects are now truncated in failure messages (improves CI log readability); NotSubset failure messages fixed to use %#v instead of %q; mock.Return removed (irrelevant, we don't use mock); vendors pmezard/go-difflib and davecgh/go-spew to reduce external deps.
  • v1.12.1: Swapped gopkg.in/yaml.v3 for go.yaml.in/yaml/v3 — reduces external dependency surface and moves to the actively-maintained YAML fork. Testify's release notes call this "the first release which has the minimum dependencies practical."

Best Practices

Maintainers recommend preferring specific assertions (Empty, Len, Contains) over generic boolean checks for clearer failure output — this project already follows that convention. Bound asserters (assert.New(t)) are recommended for tests with many assertions — already used 218 times.

Improvement Opportunities

🏃 Quick Wins

  • Bump github.com/stretchr/testify from v1.11.1v1.12.1 in go.mod. Low-risk minor bump (no breaking API changes affecting assert/require) that picks up the long-object truncation improvement, helping CI output readability for large struct diffs (e.g. internal/config validation tests).
  • Run go get github.com/stretchr/testify@v1.12.1 && go mod tidy then re-run make test. Note the v1.12.1 yaml dependency swap changes an indirect dependency, so go.sum will need updating.

✨ Feature Opportunities

  • None of the new v1.12.x features map to an immediate functional gap, but the improved long-object truncation directly helps the large config validation test suite that asserts on big struct diffs.

📐 Best Practice Alignment

  • Already well aligned: assertions favor specific matchers over generic True/Equal(true, ...) patterns, and require vs assert semantics are used correctly.

🔧 General Improvements

  • Consider enabling testifylint (available but disabled per .golangci.yml) on a per-package basis for newly-touched files, since existing code already conforms to its rules — providing a regression guard without a mass refactor.

Module Summary

Field Value
Module github.com/stretchr/testify
Version v1.11.1 (go.mod) → recommend v1.12.1
Repository https://github.com/stretchr/testify
Latest Release v1.12.1 (2026-08-19)
Last Reviewed 2026-08-20

Key Features

  • assert/require rich assertion library with 60+ matchers
  • mock package for interface mocking (unused here)
  • suite package for test suite lifecycle management (unused here)
  • Now vendors go-difflib/go-spew and uses go.yaml.in/yaml/v3 to minimize transitive deps

References

Recommendations

  1. Bump testify to v1.12.1 for improved failure-message readability and a leaner dependency tree.
  2. Run go mod tidy and full test suite after the bump to catch any transitive yaml dependency issues.
  3. Optionally scope-enable testifylint for new/modified files given existing code is already compliant.

Next Steps

  • Open a small PR bumping the testify version and running make agent-finished to validate.
  • Track transitive go.yaml.in/yaml/v3 addition in go.sum diffs during review.

Generated by Go Fan

Generated by Go Fan · auto · 46.3 AIC · ⊞ 11.9K ·

  • expires on Aug 27, 2026, 7:23 AM UTC

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions