blob: a0b953aa5cf60d46e68b7cc24c8607f123d26e96 [file] [log] [blame]
khenaidooac637102019-01-14 15:44:34 -05001// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
2//
Abhay Kumara2ae5992025-11-10 14:02:24 +00003// # Note
4//
5// All functions in this package return a bool value indicating whether the assertion has passed.
6//
7// # Example Usage
khenaidooac637102019-01-14 15:44:34 -05008//
9// The following is a complete example using assert in a standard test function:
khenaidooac637102019-01-14 15:44:34 -050010//
Abhay Kumara2ae5992025-11-10 14:02:24 +000011// import (
12// "testing"
13// "github.com/stretchr/testify/assert"
14// )
khenaidooac637102019-01-14 15:44:34 -050015//
Abhay Kumara2ae5992025-11-10 14:02:24 +000016// func TestSomething(t *testing.T) {
khenaidooac637102019-01-14 15:44:34 -050017//
Abhay Kumara2ae5992025-11-10 14:02:24 +000018// var a string = "Hello"
19// var b string = "Hello"
khenaidooac637102019-01-14 15:44:34 -050020//
Abhay Kumara2ae5992025-11-10 14:02:24 +000021// assert.Equal(t, a, b, "The two words should be the same.")
22//
23// }
khenaidooac637102019-01-14 15:44:34 -050024//
25// if you assert many times, use the format below:
26//
Abhay Kumara2ae5992025-11-10 14:02:24 +000027// import (
28// "testing"
29// "github.com/stretchr/testify/assert"
30// )
khenaidooac637102019-01-14 15:44:34 -050031//
Abhay Kumara2ae5992025-11-10 14:02:24 +000032// func TestSomething(t *testing.T) {
33// assert := assert.New(t)
khenaidooac637102019-01-14 15:44:34 -050034//
Abhay Kumara2ae5992025-11-10 14:02:24 +000035// var a string = "Hello"
36// var b string = "Hello"
khenaidooac637102019-01-14 15:44:34 -050037//
Abhay Kumara2ae5992025-11-10 14:02:24 +000038// assert.Equal(a, b, "The two words should be the same.")
39// }
khenaidooac637102019-01-14 15:44:34 -050040//
Abhay Kumara2ae5992025-11-10 14:02:24 +000041// # Assertions
khenaidooac637102019-01-14 15:44:34 -050042//
43// Assertions allow you to easily write test code, and are global funcs in the `assert` package.
44// All assertion functions take, as the first argument, the `*testing.T` object provided by the
45// testing framework. This allows the assertion funcs to write the failings and other details to
46// the correct place.
47//
48// Every assertion function also takes an optional string message as the final argument,
49// allowing custom error messages to be appended to the message the assertion method outputs.
50package assert