testify

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0, MIT Imports: 0 Imported by: 0

README

Build Status Go Report Card PkgGoDev

Testify - Thou Shalt Write Tests

Go code (golang) set of packages that provide many tools for testifying that your code will behave as you intend.

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

Why this fork?

From the maintainers of testify, it looks like a v2 is coming up, but they'll do it at their own pace.

We like all the principles they put forward to build this v2. See discussion about v2

However, at go-openapi we would like to address the well-known issues in testify with different priorities.

  1. We want first to remove all external dependencies.

For all our libraries and generated test code we don't want test dependencies to drill farther than import github.com/go-openapi/testify, but on some specific (and controlled) occasions.

In this fork, all external stuff is either internalized (go-spew, difflib), removed (mocks, suite, http) or specifically enabled by importing a specific module (github.com/go-openapi/testify/enable/yaml).

  1. We want to remove most of the chrome that has been added over the years

The go-openapi libraries and the go-swagger project make a rather limited use of the vast API provided by testify.

With this first version of the fork, we have removed mocks and suite, which we don't use. They might be added later on, with better controlled dependencies.

In the forthcoming maintenances of this fork, much of the "chrome" or "ambiguous" API will be pared down. There is no commitment yet on the stability of the API.

Chrome would be added later: we have the "enable" packages just for that.

  1. We hope that this endeavour will help the original project with a live-drill of what a v2 could look like. We are always happy to discuss with people who face the same problems as we do: avoid breaking changes, APIs that became bloated over a decade or so, uncontrolled dependencies, conflicting demands from users etc.

What's next with this project?

  1. The first release comes with zero dependencies and an unstable API (see below our use case)
  2. This project is going to be injected as the main and sole test dependency of the go-openapi libraries and the go-swagger tool
  3. Valuable pending pull requests from the original project could be merged (e.g. JSONEqBytes) or transformed as "enable" modules (e.g. colorized output)
  4. Unclear assertions may be provided an alternative verb (e.g. InDelta)
  5. Since we leveled the go requirements to the rest of the go-openapi (currently go1.24) quite a bit of relinting is ahead.

Usage at go-openapi

At this moment, we have identified the following usage in our tools. This API shall remain stable.

Condition
Contains,Containsf
Empty,Emptyf
Equal,Equalf
EqualError,EqualErrorf
EqualValues,EqualValuesf
Error,Errorf
ErrorContains
ErrorIs
Fail,Failf
FailNow
False,Falsef
Greater
Implements
InDelta,InDeltaf
IsType,IsTypef
JSONEq,JSONEqf
Len,Lenf
Nil,Nilf
NoError,NoErrorf
NotContains,NotContainsf
NotEmpty,NotEmptyf
NotEqual
NotNil,NotNilf
NotPanics
NotZero
Panics,PanicsWithValue
Subset
True,Truef
YAMLEq,YAMLEqf
Zero,Zerof

Installaton

To use this package in your projects:

    go get github.com/stretchr/testify

Get started

Features include:

Examples

See [the original README)(./original.md)

Licensing

All go-openapi projects are distributed under an Apache 2 license

The original project is licensed under the terms of the MIT license, and this fork has kept the original license.

This project is therefore dual-licensed.

Internalized libraries come this their original licensing terms:

  • go-difflib was copied with the original license from its author (Patrick Nezard)
  • go-spew was copied with the original license from its author (Dave Cheney)

SPDX-License-Identifier: Apache-2.0 SPDX-License-Identifier: MIT

Internalized libraries:

SPDX-License-Identifier: ISC SPDX-License-Identifier:

Contributing

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

When submitting an issue, we ask that you please include a complete test function that demonstrates the issue. Extra credit for those using Testify to write the test code that demonstrates it.

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

Original README

Documentation

Overview

Module testify is a set of packages that provide many tools for testifying that your code will behave as you intend.

Testify contains the following packages:

The github.com/stretchr/testify/assert package provides a comprehensive set of assertion functions that tie in to the Go testing system. The github.com/stretchr/testify/require package provides the same assertions but as fatal checks.

A golangci-lint compatible linter for testify is available called testifylint.

Directories

Path Synopsis
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
internal/unsafetests
This package exists just to isolate tests that reference the unsafe package.
This package exists just to isolate tests that reference the unsafe package.
yaml
Package yaml is just an indirection to handle YAML deserialization.
Package yaml is just an indirection to handle YAML deserialization.
internal
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.
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