testify

package module
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

README

Testify/v2

Tests Coverage CI vuln scan CodeQL

Release Go Report Card CodeFactor Grade License

Doc GoDoc Discord Channel go version Top language Commits since latest release


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.

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

Main features:

Announcements

  • 2025-12-19 : new community chat on discord
    • a new discord community channel is available to be notified of changes and support users
    • our venerable Slack channel remains open, and will be eventually discontinued on 2026-03-31

You may join the discord community by clicking the invite link on the discord badge (also above). Discord Channel

Or join our Slack channel: Slack Channelslack-badge

Status

Design and exploration phase. Feedback, contributions and proposals are welcome.

Recent news

✅ Fully refactored how assertions are generated and documented.

✅ Fixed hangs & panics when using spew. Fuzzed spew.

✅ Fixed go routine leaks with EventuallyWithT and co.

✅ Added Kind & NotKind

✅ Fix deterministic order of keys in diff

✅ Fixed edge cases with InDelta, InEpsilon

✅ Fixed edge cases with EqualValues

✅ Fixed wrong logic with IsNonIncreasing, InNonDecreasing

✅ Added opt-in support for colorized output

✅ Introduced generics: 38 new type-safe assertions with generic types (doc: added usage guide, examples and benchmark)

See also our ROADMAP.

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.

    import (
        "testing"
    )
    ...
    
    const expected = "expected result"

	result := printImports(input)
	if result != expected {
		t.Errorf(
            "Expected: %s. Got: %s", expected, result, 
        )

        return
	}

Becomes:

    import (
        "testing"
        "github.com/go-openapi/testify/v2/require"
    )
    ...

    const expected = "expected result"

	require.Equalf(t,
        expected, printImports(input), "Expected: %s. Got: %s",
        expected, result, 
    )

Usage at go-openapi and go-swagger

This fork now fully replaces the original project for all go-openapi projects, thus reducing their dependencies footprint.

Go-swagger will be adapted over Q1 2026.

Features will probably be added to support our main use cases there.

Change log

See https://github.com/go-openapi/testify/releases

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.

Other documentation

Cutting a new release

Maintainers can cut a new release by either:

  • running this workflow (recommended)
  • or :
    1. preparing go.mod files with the next tag, merge
    2. pushing a semver tag
    • signed tags are preferred
    • The tag message is prepended to release notes

Documentation

Overview

Package testify provides comprehensive assertion packages for Go testing.

Overview

This is the go-openapi fork of testify, designed with zero external dependencies and a focus on maintainability. The codebase uses code generation more extensively than the original testify. This helps maintain consistency across all assertion variants.

Packages

The assert package provides a comprehensive set of assertion functions that integrate with Go's testing framework. Assertions return boolean values allowing tests to continue after failures.

The require package provides the same assertions but with fatal checks that stop test execution immediately on failure via testing.T.FailNow.

Key Differences from stretchr/testify

This fork prioritizes:

  • Zero external dependencies (go-spew and difflib are internalized)
  • Removed mock and suite packages (favor the use mockery or similar specialized tools instead)
  • Optional features via enable packages (e.g., enable/yaml for YAML assertions)
  • Code generation ensures consistency across 76 assertion functions × 8 variants

Optional Features

YAML assertions require importing the enable package:

import _ "github.com/go-openapi/testify/v2/enable/yaml"

Without this import, YAMLEq and YAMLEqf will panic loudly with a helpful error message.

Note on testifylint

The golangci-lint compatible linter testifylint is designed for stretchr/testify and will not work with this fork as it checks only for the original dependency.

Directories

Path Synopsis
enable/colors
Package colors is an indirection to handle colorized output.
Package colors is an indirection to handle colorized output.
enable/yaml
Package yaml is an indirection to handle YAML deserialization.
Package yaml is an indirection to handle YAML deserialization.
Package enable contains go modules with extra-dependencies.
Package enable contains go modules with extra-dependencies.
internal
assertions
Package assertions holds the internal implementation of all the helper functions exposed by testify.
Package assertions holds the internal implementation of all the helper functions exposed by testify.
assertions/enable
Package enable allows to register extra features.
Package enable allows to register extra features.
assertions/enable/yaml
Package yaml is an indirection to handle YAML deserialization.
Package yaml is an indirection to handle YAML deserialization.
assertions/unsafetests
Package unsafetests exists only to isolate tests that reference the unsafe package.
Package unsafetests exists only to isolate tests that reference the unsafe package.
difflib
Package difflib is a partial port of Python difflib module.
Package difflib is a partial port of Python difflib module.
spew
Package spew implements a deep pretty printer for Go data structures to aid in debugging.
Package spew implements a deep pretty printer for Go data structures to aid in debugging.
spew/testsrc
Package testsrc is a package for testing spew with cgo.
Package testsrc is a package for testing spew with cgo.
Package require implements the same assertions as the assert package but stops test execution when a test fails.
Package require implements the same assertions as the assert package but stops test execution when a test fails.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL