Repolode
stretchr

stretchr/testify

A Go testing toolkit providing assertions, mocks, and a suite structure that works with the standard go test runner.

Stars
26,229
Forks
1,870
Open issues
402
Last commit
6 days ago

What is it?

Testify is a Go library for writing tests more concisely. Its assert package offers helper functions for equality, nil checks, and many other common comparisons, and reports failures with readable output through the normal go test mechanism. The require package provides the same functions but stops the current test on failure instead of returning a boolean.

The mock package lets you build mock objects by embedding a Mock type and declaring expected calls and return values, then verify that those expectations were met. The suite package lets you group tests as struct methods with setup and teardown hooks, and run them through a standard Test function.

The project is maintained at v1, and the repository does not accept breaking changes there. Its packages install with a single go get command.

Key features

  • 01Assertion functions for equality, nil checks, and other common comparisons with readable failure output
  • 02require package that stops the test immediately on failure
  • 03Mock objects with expected calls, return values, and verification
  • 04Test suites built as structs with setup and teardown hooks

Use cases

  • Writing unit tests for Go services and libraries with concise assertions
  • Mocking interfaces to isolate the code under test from external dependencies
  • Organizing related tests with shared setup and teardown in a suite

Quick start

  1. 1

    Install testify with go get

    go get github.com/stretchr/testify
  2. 2

    Import the assert package in your test file and write a test

Things to know

  • The suite package does not support parallel tests.
  • The http package is deprecated.

In collections

Topics

FAQ

What is testify?
A Go testing toolkit providing assertions, mocks, and a suite structure that works with the standard go test runner. Testify is a Go library for writing tests more concisely. Its assert package offers helper functions for equality, nil checks, and many other common comparisons, and reports failures with readable output through the normal go test mechanism. The require package provides the same functions but stops the current test on failure instead of returning a boolean.
Is testify free to use? What license does it have?
testify is open source under the MIT license. Check the license terms before using it in commercial products.
Is testify still maintained?
Actively maintained. The last commit to testify was on Oct 19, 2026.
What can I use testify for?
Writing unit tests for Go services and libraries with concise assertions Mocking interfaces to isolate the code under test from external dependencies Organizing related tests with shared setup and teardown in a suite
How do I install testify?
Install testify with go get: go get github.com/stretchr/testify Import the assert package in your test file and write a test
Where can I get testify?
The source code and installation instructions are on GitHub: https://github.com/stretchr/testify

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects