Test Function Has Wrong Signature

wrong signature for TestFoo, must be: func TestFoo(t *testing.T)

Quick Answer

Test functions must take exactly one parameter of type *testing.T and return nothing. Benchmark functions use *testing.B.

Why This Happens

Go's testing framework discovers tests by function name and signature. A function named TestXxx must accept exactly *testing.T as its sole parameter and return no values. If the signature is wrong, the test runner ignores it or reports an error.

The Problem

func TestAdd(a, b int) int { // wrong signature
    return a + b
}

The Fix

func TestAdd(t *testing.T) {
    result := Add(2, 3)
    if result != 5 {
        t.Errorf("Add(2, 3) = %d, want 5", result)
    }
}

Step-by-Step Fix

  1. 1

    Identify the wrong signature

    Find test functions that do not match the func TestXxx(t *testing.T) signature.

  2. 2

    Fix the signature

    Change the function to accept *testing.T as the only parameter and return nothing.

  3. 3

    Move test logic inside

    Use t.Errorf, t.Fatal, or t.Run for assertions and sub-tests.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free