Skip to content

[Code Quality] Standardize table-driven test naming convention to tests/tt #12738

@github-actions

Description

@github-actions

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 := []struct with for _, tt := range tests
  • 33 instances use testCases := []struct with for _, 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

  1. Find files using testCases pattern:

    rg "testCases := \[\]struct" --type go -g "*_test.go" --files-with-matches
  2. Semi-automated refactor (manual review required for scoped variables):

    • Replace testCases := []structtests := []struct
    • Replace for _, tc := range testCasesfor _, tt := range tests
    • Replace all tc.tt. within each test function scope
  3. Add linter rule - Use golangci-lint varnamelen to prefer tt over tc

  4. 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 tt over tc
  • 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions