Categorygithub.com/go73/testify-extra
repository
0.1.0
Repository: https://github.com/go73/testify-extra.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

Testify Extra

Extras to the stretchr/testify test library.

Delegating Equal()/NotEqual()

Testify's Equal() implementation uses reflect.DeepEqual(...) to check for equality. This makes sense when comparing most values, however there are certain types that are semantically equivalent even though they are not strictly equal using this method.

In such cases, the de facto standard is to use an Equal(T) bool method to define semantic equivalence. This is used within the Go standard library:

And is also adopted by some third-party libraries:

assert example shown here, but the require version is available as well:

package yours

import (
	"testing"
	"time"
	"github.com/go37/testify-extra/assert"
)

func TestSomething(t *testing.T) {

	// assert equality
	assert.Equal(t,
		time.UnixMilli(123),
		time.UnixMilli(123).In(time.FixedZone("UTC-1", -1*60*60)),
		"they should be equal")

	// assert inequality
	assert.NotEqual(t,
		time.UnixMilli(123), time.UnixMilli(456),
		"they should not be equal")

}

Installation

go get github.com/go73/testify-extra