| title | type | description | weight |
|---|---|---|---|
Testify v2 |
home |
The v2 our test wanted |
1 |
{{% notice info %}}
This is the home of github.com/go-openapi/testify/v2, an active, opinionated fork of github.com/stretchr/testify.
{{% /notice %}}
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.
{{% button href="https://github.com/go-openapi/testify/fork" hint="fork me on github" style=primary icon=code-fork %}}Fork me{{% /button %}} Design and exploration phase. Feedback, contributions and proposals are welcome.
See our ROADMAP.
See why we wanted a v2.
Import this library in your project like so.
go get github.com/go-openapi/testify/v2... and start writing tests. Look at our examples.
testify simplifies your test assertions like so.
{{< cards >}} {{% card title="Standard library" %}}
import (
"testing"
)
...
const expected = "expected result"
result := printImports(input)
if result != expected {
t.Errorf(
"Expected: %s. Got: %s",
expected, result,
)
return
}{{% /card %}}
{{% card title="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,
){{% /card %}} {{< /cards >}}
Assertion functions that support go generic types are suffixed with T (for "Type safety").
A formatted variant suffixed with Tf is also exposed.
Obviously, the Assertion type cannot be extended with generic methods, as of go1.25.
{{< cards >}} {{% card title="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){{% /card %}} {{% card title="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){{% /card %}} {{< /cards >}}
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.
Feel free to submit issues, fork the repository and send pull requests!
{{% notice style="primary" title="Info" icon="info" %}}
Code generation is used. Run go generate ./... to update generated files.
{{% /notice %}}
See also our CONTRIBUTING guidelines.
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:
- Generics Guide - Type-safe assertions with 38 generic functions
- Migration Guide - Migrating from stretchr/testify v1
- Changes from v1 - All changes and improvements in v2
- Benchmarks - Performance improvements in v2
Reference:
- API Reference - Complete assertion catalog organized by domain
{{< children type="card" description="true" >}}