📖 3 min read (~ 600 words).

Testify v2

Info

This is the home of github.com/go-openapi/testify/v2, an active, opinionated fork of github.com/stretchr/testify.

Testify v2 - The v2 our tests wanted

A set of go packages that provide tools for testifying (verifying) that your code behaves as you intended.

This is the go-openapi fork of the great testify package.

Status

Fork me Design and exploration phase completed. The published API is now stable: moving forward, API changes will remain backward-compatible with v2.4.0.

See our ROADMAP.

Motivation

See why we wanted a v2.

Getting started

Import this library in your project like so.

go get github.com/go-openapi/testify/v2

… and start writing tests. Look at our examples.

Basic usage

testify simplifies your test assertions like so.

  • Standard library
    import (
            "testing"
        )
        ...
        
        const expected = "expected result"
    
    	  result := printImports(input)
    	  if result != expected {
    		  t.Errorf(
            "Expected: %s. Got: %s",
            expected, result, 
          )
    
          return
    	  }
  • testify
    import (
            "testing"
    
            "github.com/go-openapi/testify/v2/require"
        )
        ...
    
        const expected = "expected result"
    
    	  result := printImports(input)
    	  require.Equalf(t, expected, result,
            "Expected: %s. Got: %s", expected, result, 
        )

Usage with generics

Assertion functions that support go generic types are suffixed with T (for “Type safety”). A formatted variant suffixed with Tf is also exposed.

Build with go1.27 or newer and every generic assertion is also a method of the Assertions type: a.EqualT(expected, result) alongside require.EqualT(t, expected, result). go1.27 is the first release that accepts type parameters on methods; on go1.25 and go1.26 those methods are excluded by a //go:build go1.27 guard, and the package-level functions below are the only form available.

  • EqualT
    import (
            "testing"
    
            "github.com/go-openapi/testify/v2/require"
        )
        ...
        
        const expected = "Hello World"
        var input := "World"
    
    	result := someRamblingTextGeneration(input)
        require.EqualT(t, expected, result)
  • InDeltaT
    import (
            "testing"
    
            "github.com/go-openapi/testify/v2/require"
        )
        ...
        
        const (
            expected = 1.00
            delta = 1E-6
        )
        var input = 1.01
    
    	result := someComplexComputation(input)
        require.InDeltaT(t, expected, input, delta)

Licensing

SPDX-FileCopyrightText: Copyright 2025 go-swagger maintainers

This library ships under the SPDX-License-Identifier: Apache-2.0.

See the license NOTICE, which recalls the licensing terms of all the pieces of software distributed with this fork, including internalized libraries.


We’d like to give credit and pay a big and loud thank you to the people who wrote these amazing pieces of software. We maintain their original work here and continue improving it.

  • Mat Ryer, Tyler Bunnell and the stretchr/testify contributors - who made this new project possible
  • thank you to the maintainers of that library, @ccoveille, @dolmen for their feedback and advice
  • Dave Collins dave@davec.name who wrote the spew library
  • Patrick Mezard who wrote the difflib library - originally a go port from python’s difflib

Also special thanks to:

  • Gregory Petrosyan (@flyingmutant) - we use his amazing “rapid” library for our integration tests, with property-based testing
  • the authors and maintainers of github.com/yaml/go-yaml, which we rely on for our YAML work

Contributing

Feel free to submit issues, fork the repository and send pull requests!

Info

Code generation is used. Run go generate ./... to update generated files.

See also our CONTRIBUTING guidelines.


See Also

Getting Started:

  • Usage Guide - API conventions and how to navigate the documentation
  • Tutorial - Best practices and patterns for writing great tests
  • Examples - Practical code examples for common testing scenarios

Advanced Topics:

Reference:


  • Index Of Assertion Domains.

    Find the assertion function you need for your data.

  • Guides, examples and tutorials.