Testify is a Go library that adds assertions, mocking, and test-suite structure on top of the standard testing package. It targets Go developers who want more readable test failures and less boilerplate than raw if checks against t.Error or t.Fatal, without pulling in a full replacement test runner.
The library ships as four main packages: assert, require, mock, and suite. Each works with go test directly, so there's no separate test binary or runner to learn.
Equal, NotEqual, and Nil that print readable failure messages and return a bool so you can branch on assertion results.assert API but calls t.FailNow() on failure, stopping the test immediately instead of continuing with a false assumption.mock.Mock, setting up expectations with On() and Return(), and verifying calls with AssertExpectations.SetupTest/TearDownTest hooks, useful for grouping related tests that share setup logic.assert.New(t) and suite embedding give you assertion methods without repeating the t argument on every call.mockery tool to autogenerate mock implementations from interfaces.Testify fits projects already using Go's standard testing package that want clearer failure output and reusable assertion helpers, rather than a full BDD framework. It's a good match for tests that need mock objects for interfaces (external services, repositories, clients) without hand-writing every mock method's bookkeping. Suites help when you have multiple tests sharing setup/teardown logic, such as spinning up a test database connection once per suite run.
It's not a fit if you need parallel test execution within a suite. The suite package doesn't support t.Parallel(), per an open issue in the repo. If your project needs a full mocking framework with automatic mock generation baked in, you'll still want to pair testify with mockery or write mocks by hand. And if you prefer table-driven tests with plain standard-library assertions and no extra dependency, testify adds a package you may not need.
Install with go get:
go get github.com/stretchr/testify
This makes the following packages available:
github.com/stretchr/testify/assert
github.com/stretchr/testify/require
github.com/stretchr/testify/mock
github.com/stretchr/testify/suite
github.com/stretchr/testify/http (deprecated)
Import assert in a test file:
package yours
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSomething(t *testing.T) {
assert.True(t, true, "True is true!")
}
To update to the latest version later:
go get -u github.com/stretchr/testify
The project supports the most recent major Go versions from 1.19 onward.