Skip to content
Latchkey

How to Run Go Tests in Parallel in CI

Go parallelism has two knobs: t.Parallel() runs tests within a package concurrently, and go test -p controls how many packages run at once.

Mark independent tests with t.Parallel(), then tune package-level concurrency with go test -p and per-package parallelism with -parallel.

Steps

  • Call t.Parallel() at the top of tests that are independent.
  • Set -p to bound how many packages run concurrently.
  • Set -parallel to bound parallel tests within a package.

Test code

thing_test.go
func TestThing(t *testing.T) {
    t.Parallel()
    // ... independent assertions
}

Terminal

Terminal
go test -p 4 -parallel 8 ./...

Gotchas

  • t.Parallel() tests share package-level state; guard globals or they will race.
  • Run with -race in CI to catch data races that parallelism exposes.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →