Repository navigation
[go-fan] Go Module Review: testify #5374
Closed
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
🐹 Go Fan Report: stretchr/testify
Module Overview
Testify is Go's most popular testing toolkit (24k+ stars), providing expressive assertion methods, mock objects, and test suite structures. It enhances the standard
testingpackage with readable assertions and better error messages.Repository: https://github.com/stretchr/testify
Version Used: v1.11.1 (latest release, August 2025)
Status: ✅ Up to date
Current Usage in gh-aw
Adoption Metrics
assert.*: 229 assertionsrequire.*: 253 assertionsmock: Not usedsuite: Not usedWhere It's Used
Testify adoption is concentrated in 12 newer test files:
Workflow Package (10 files):
pkg/workflow/script_registry_test.go- Script bundling and caching testspkg/workflow/gateway_test.go- MCP gateway configuration parsingpkg/workflow/error_message_quality_test.go- Error message validationpkg/workflow/safe_outputs_*.go(7 files) - Safe outputs validation testspkg/workflow/activation_outputs_always_declared_test.gopkg/workflow/sandbox_test.go- Sandbox registry testsCLI Package (2 files):
pkg/cli/completions_test.go- Shell completion testspkg/cli/completions_integration_test.goMost Common Assertions
Top 10 assertion patterns from our analysis:
assert.Equal()- Value equality checksassert.NotEmpty()/assert.Empty()- Emptiness validationassert.Contains()/assert.NotContains()- Substring/element presenceassert.Len()- Collection length verificationrequire.NoError()- Critical error checks (stops on failure)assert.True()/assert.False()- Boolean assertionsassert.Nil()/assert.NotNil()- Nil pointer checksrequire.NotNil()- Critical nil checksrequire.NotEmpty()- Critical non-empty checksassert.Error()- Error expectation validationResearch Findings
Recent Updates
v1.11.1 (August 2025) - Bug Fix Release
Fixed argument matching behavior for mutating stringers in the mock package. Restored pre-v1.11.0 behavior where stringer methods are always called.
v1.11.0 (August 2025) - Major Performance & Features Release
Key improvements:
CallerInfo, mock diff output,Eventually/NeverIsNotTypefor negative type checksJSONEqandYAMLEqnow shortcut on identical stringsErrorAs,ErrorIs,Subset/NotSubsetmock.NotBefore()Best Practices from Maintainers
assert.New(t)for multiple assertions - Reduces repetitionrequirefor preconditions - Setup, file operations, critical checksassertfor test assertions - See all failures, not just the firsttestifylint- Catch common anti-patterns via golangci-lintAssertExpectations(t)Key Observation: Huge Untapped Potential
97.8% of tests (522 files) still use standard library testing!
This represents a massive opportunity to improve test maintainability and readability across the entire codebase.
Improvement Opportunities
🏃 Quick Wins
1. Use
assert.New(t)for Cleaner CodeCurrent pattern (from
gateway_test.go):Better pattern:
Impact: Less visual noise, recommended by testify docs
Files Affected: All 12 testify test files
2. Enable
testifylintin golangci-lintAdd to
.golangci.yml:Catches:
assert.True(len(x) > 0)→assert.NotEmpty(x))3. Use Specialized Assertions
Current:
assert.True(t, len(results) > 0, "results should not be empty")Better:
assert.NotEmpty(t, results, "results should not be empty")Benefit: More descriptive failure messages showing actual values
✨ Feature Opportunities
1. Gradually Adopt Testify Across the Codebase
Current State: Only 2.2% adoption (12 of 534 test files)
Strategy:
Benefits:
Files to Prioritize:
pkg/workflow/2. Leverage Suite Package for Integration Tests
Several test files would benefit from setup/teardown structure:
pkg/cli/completions_integration_test.go- Creates temp directoriespkg/workflow/safe_outputs_*_test.go- Common compiler setuppkg/workflow/sandbox_test.go- Shared registry initializationExample Refactor:
t.Parallel()- use only for integration tests3. Add Mock Package for External Dependencies
Currently: Zero mock usage detected
Opportunities:
pkg/cli/testsExample (for
pkg/workflow/gateway_test.go):4. Use
EventuallyWithTfor Async AssertionsNew in v1.10.0+, perfect for async testing:
Potential Uses:
pkg/cli/file_tracker_test.go📐 Best Practice Alignment
1. Standardize Error Assertions
Current mixed patterns:
Recommendation:
require.NoError(t, err)for setup/preconditionsassert.Error(t, err)when expecting errorsassert.ErrorContains(t, err, "expected text")for message validation2. Add Descriptive Messages
Many assertions lack context:
Impact: Faster debugging when tests fail in CI
3. Create Project-Specific Assertion Helpers
Add to
pkg/testutil/assertions.go:🔧 General Improvements
1. Establish Testify as Standard for New Tests
Action Items:
2. Document Migration Strategy
Phased Approach:
3. Track Adoption Metrics
Monitor testify adoption over time:
Recommendations
📋 Immediate Actions (This Sprint)
assert.New(t)for cleaner code📅 Short Term (Next Quarter)
pkg/testutil/🔮 Long Term (Future Consideration)
Performance Note
Testify v1.11.0 includes significant performance improvements. Current usage in 12 files shows no performance concerns. For extremely tight performance-critical tests, standard library may still be preferred, but this is rare.
Next Steps
assert.New(t)Key Takeaway
Testify is underutilized in gh-aw! With only 2.2% adoption, there's a massive opportunity to improve test quality and maintainability. The module is mature, well-maintained, and on the latest version. Focus on gradual adoption through new tests first, then selective migration of high-value existing tests.
Module summary saved to: specs/mods/testify.md
All reactions