Skip to content

v3: use interface instead of *testing.T in test_helpers #474

@bigbes

Description

@bigbes

Refactor the test_helpers package to accept a custom T interface instead of concrete *testing.T. This makes test utilities reusable in examples, benchmarks, or custom test runners.

Types like MockDoer and MockResponse depend directly on *testing.T:

func NewMockDoer(t *testing.T, ...) *MockDoer

This tightly couples helpers to the testing package, preventing their use in:

  • Example functions (ExampleXxx)
  • Custom test frameworks
  • Non-*testing.T contexts (e.g., internal validation tools)

Define a minimal interface that captures only the methods we actually use:

// T is a subset of *testing.T used for test helpers.
type T interface {
	Helper()
	Fatalf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

Then update all functions in test_helpers to accept T instead of *testing.T.

Checklist

  • Add the T interface in test_helpers (e.g., in test_helpers/types.go).
  • Update all helper functions and structs (MockDoer, MockResponse, etc.) to use T.
  • Update existing tests to still pass *testing.T (it satisfies T automatically).
  • Modify CHANGELOG.md and MIGRATION.md accordingly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions