go vet "wrong signature for TestX, must be func TestX(t *testing.T)" in CI
The tests analyzer checks that functions named TestXxx take exactly (t *testing.T). A wrong signature would otherwise be silently skipped by the test runner, so vet reports it.
What this error means
go vet or go test reports "wrong signature for TestFoo, must be: func TestFoo(t *testing.T)".
go vet
./svc_test.go:9:1: wrong signature for TestFetch, must be: func TestFetch(t *testing.T)Common causes
The test takes the wrong parameter type
A function named TestXxx declares a different parameter (or none), so the testing package would not call it as a test.
A helper accidentally named with a Test prefix
A non-test helper was named TestXxx, colliding with the convention the runner relies on.
How to fix it
Use the standard test signature
- Change the parameter to
t *testing.T(orb *testing.BforBenchmarkXxx). - Rename the function if it is not actually a test.
- Re-run
go vet ./...andgo test ./....
svc_test.go
func TestFetch(t *testing.T) {
// ...
}Rename non-test helpers
Give helper functions a name that does not start with Test, Benchmark, Example, or Fuzz.
How to prevent it
- Run
go vet ./...in CI so mis-signed tests are caught. - Reserve the Test/Benchmark/Example/Fuzz prefixes for real test functions.
- Use table-driven tests with the standard signature.
Related guides
go vet "struct field tag not compatible with reflect.StructTag.Get" in CIFix go vet "struct field tag not compatible with reflect.StructTag.Get: bad syntax for struct tag value" in C…
go test "flag provided but not defined" in CIFix go test "flag provided but not defined: -X" in CI - a custom flag is passed before the package list, so i…
go test "no tests to run" with a -run filter in CIFix go test "testing: warning: no tests to run" in CI - the -run regular expression matched no test names, so…