-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Description
Table-driven tests use two competing naming conventions: 97.7% use tests/tt, while 2.3% use testCases/tc. This inconsistency creates unnecessary cognitive load during code review and maintenance.
Problem
Statistics:
- 1,394 instances use
tests := []structwithfor _, tt := range tests - 33 instances use
testCases := []structwithfor _, tc := range testCases
Developers must context-switch between conventions, slowing code reviews and maintenance.
Suggested Changes
Standardize on tests/tt pattern (majority convention) via automated refactoring:
Before (minority pattern in 33 files)
testCases := []struct {
name string
input int
expected int
}{
{name: "positive", input: 5, expected: 5},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := myFunc(tc.input)
require.Equal(t, tc.expected, result)
})
}After (standard pattern)
tests := []struct {
name string
input int
expected int
}{
{name: "positive", input: 5, expected: 5},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := myFunc(tt.input)
require.Equal(t, tt.expected, result)
})
}Implementation Steps
-
Find files using testCases pattern:
rg "testCases := \[\]struct" --type go -g "*_test.go" --files-with-matches
-
Semi-automated refactor (manual review required for scoped variables):
- Replace
testCases := []struct→tests := []struct - Replace
for _, tc := range testCases→for _, tt := range tests - Replace all
tc.→tt.within each test function scope
- Replace
-
Add linter rule - Use golangci-lint
varnamelento preferttovertc -
Document - Add standard to CONTRIBUTING.md
Files Affected
33 test files across the codebase (identified via ripgrep search)
Success Criteria
- Run full test suite to verify no regressions
- Manual code review of refactored files
- Add golangci-lint varnamelen rule to prefer
ttovertc - Document standard in CONTRIBUTING.md
Source
Extracted from Sergo Report: Table-Driven Test & Init Function Hygiene Analysis - 2026-01-30
Priority
Medium - Code consistency improvement, low risk
Estimated Effort
Small (1 hour) - Mostly automated find-replace with manual verification
AI generated by Discussion Task Miner - Code Quality Improvement Agent
- expires on Feb 13, 2026, 1:26 PM UTC