testing

Testing
import "testing"

Provides support for automated testing of Go packages (unit tests, benchmarks, examples).

Example

package main_test

import "testing"

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

func BenchmarkAdd(b *testing.B) {
    for i := 0; i < b.N; i++ {
        _ = 2 + 3
    }
}

Key Types & Functions

TBMRunErrorfFatalSkipCleanupParallel

About testing

The testing package (imported as testing) belongs to the Testing category of Go packages. Provides support for automated testing of Go packages (unit tests, benchmarks, examples).

Go's standard library is one of the language's greatest strengths, providing production-ready implementations for networking, cryptography, encoding, I/O, and more. The testing package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.

When using testing in production, follow Go best practices: handle errors explicitly, use context for cancellation and timeouts, prefer composition over inheritance, and write table-driven tests. The Go documentation at pkg.go.dev provides comprehensive API references and examples for every exported type and function.

Related Packages