stretchr/testify

Testing
import "github.com/stretchr/testify"

A toolkit with assertions, mocks, and test suites for Go testing.

Example

package main_test

import (
    "testing"
    "github.com/stretchr/testify/assert"
)

func TestAdd(t *testing.T) {
    assert.Equal(t, 5, 2+3)
    assert.NotNil(t, "hello")
    assert.Contains(t, "hello world", "hello")
}

Key Types & Functions

assert.Equalassert.NotNilrequire.NoErrormock.Mocksuite.Suite

About stretchr/testify

The stretchr/testify package (imported as github.com/stretchr/testify) belongs to the Testing category of Go packages. A toolkit with assertions, mocks, and test suites for Go testing.

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 stretchr/testify package follows Go's philosophy of simplicity and composability — small, focused packages that combine through interfaces like io.Reader and io.Writer.

When using stretchr/testify 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