# README
assert-go
Package assert simplifies writing test assertions.
Output will contain a helpful diff rendered using as well as the source code of
the expression being tested. For example, if you call assert.Equal(t, car.Name, "Porsche")
, the error message will include "car.Name".
Additional options and custom comparators can be registered using
RegisterOptions
, or passed in as the last parameter to the function call. For
example, to indicate that unexported fields should be ignored on MyType
, you
can use:
assert.RegisterOptions(
cmpopts.IgnoreUnexported(MyType{}),
)
See the go-cmp docs for more options.
Usage
func Test(t *testing.T) {
message := "foo"
assert.Equal(t, message, "bar")
// message (-got +want): {string}:
// -: "foo"
// +: "bar"
p := Person{Name: "Alice"}
assert.Equal(t, p, Person{Name: "Bob"})
// p (-got +want): {domain_test.Person}.Name:
// -: "Alice"
// +: "Bob"
}
# Functions
Contains asserts that got contains want.
Empty asserts that got is empty.
Equal asserts that got and want are assertEqual.
ErrorContains asserts that the error message contains the wanted string.
False asserts that got is false.
Ignore configures assert to ignore the specified field paths when testing equality.
JSONEqual asserts that got and want are equal when represented as JSON.
JSONLookup fetches a value from a JSON object using the path expression.
JSONPath asserts that evaluating the path expression against the subject results in want.
Match asserts that got matches the regex want.
Must asserts that err is nil, calling t.Fatal otherwise.
Nil asserts that got is nil.
NotEmpty asserts that got is not empty.
NotEqual asserts that got and want are not equal.
NotNil asserts that got is not nil.
RegisterOptions registers a default option for all tests in the current package.
True asserts that got is true.