Skip to content

testify

A Go testing toolkit with readable assertions, mocks, and test suites that work with the standard library.

Stars
26.2k
Forks
1.9k
Licence
MIT
Language
Go
Last update
18 days ago
Type
Library

What it is

Testify is a set of Go packages that help you check that your code behaves as you expect. It offers an assert package with readable checks that print clear failure messages, a require package that stops a test on failure, a mock package for stand-in objects, and a suite package for grouping tests as structs. It plugs into Go's built-in go test command.

  • Write test assertions like assert.Equal and assert.Nil with optional failure messages
  • Replace a dependency with a mock object and verify the expected calls happened
  • Group related tests into a suite with setup methods that run before each test
  • Generate mock code from interfaces using the mockery tool mentioned in the README

Great for

  • Go developers who want more readable test assertions than the standard library provides
  • Teams writing unit tests that depend on external interfaces and need mock objects
  • Developers who want to organize related tests with setup and teardown methods

Not ideal for

  • Projects not written in Go, since it is a Go-only library
  • People looking for a standalone application or end-user tool
  • Anyone needing parallel suite tests, because the README says the suite package does not support them (issue #934)
Step-by-step guide: how to use testifyInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Go

    Install testify

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

    Run it

    • Install the package with go get as shown above
    • Import github.com/stretchr/testify/assert in a _test.go file
    • Write a function named TestSomething that takes *testing.T and calls assert functions
    • Run go test to see the results
  3. 3

    Get the most out of it

    • Use require instead of assert when a failed check should stop the test immediately
    • Use assert.New(t) to avoid repeating the t argument across many assertions
    • Add testifylint through golangci-lint to catch common mistakes, as the README suggests
    • Use mock.Anything as a placeholder for arguments that change between runs

Downloads

Strengths

  • Produces friendly, easy-to-read failure descriptions
  • Works with Go's normal go test command and testing.T
  • Widely used, with a long-established API and an MIT license

Trade-offs

  • The README says v1 is maintained without breaking changes, and a v2 is only under discussion
  • The suite package does not support parallel tests
  • Mocks are written by hand unless you add a separate generator such as mockery

How it compares

ProjectStarsTypeLevelUpdatedBest for
testify (this)26.2kLibrarybeginner18 days agoGo developers who want more readable test assertions than the standard library provides
mockito15.5kLibrarybeginner8 days agoJava developers writing unit tests for classes with external dependencies
chromedp13.3kLibraryintermediate4 days agoGo developers who want to automate or test web pages in code
learn-go-with-tests23.9kLearning resourcebeginner11 days agoDevelopers who are new to Go and want a guided, hands-on tutorial
imgui76.9kLibraryintermediate6 days agoGame developers who want an in-engine debug or tools panel
bubbletea45.6kLibraryintermediate5 days agoGo developers who want to build interactive command-line tools with a visual interface

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.