[Go] Run selected tests with go test -run

Created on November 30, 2026

Use -run with a regular expression that matches the tests to run. Suppose a package has these two tests.

package calc

import "testing"

func TestAdd(t *testing.T) {
    t.Log("TestAdd")
}

func TestSubtract(t *testing.T) {
    t.Log("TestSubtract")
}

Use ^TestAdd$ to match the complete name TestAdd. The -v flag displays the test that ran.

go test -v -run '^TestAdd$'

The output shows only TestAdd.

=== RUN   TestAdd
    calc_test.go:6: TestAdd
--- PASS: TestAdd (0.00s)
PASS

Reference

Go