blob: a0b953aa5cf60d46e68b7cc24c8607f123d26e96 [file] [log] [blame]
Scott Baker2c1c4822019-10-16 11:02:41 -07001// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
2//
Abhay Kumar40252eb2025-10-13 13:25:53 +00003// # Note
4//
5// All functions in this package return a bool value indicating whether the assertion has passed.
6//
7// # Example Usage
Scott Baker2c1c4822019-10-16 11:02:41 -07008//
9// The following is a complete example using assert in a standard test function:
Scott Baker2c1c4822019-10-16 11:02:41 -070010//
Abhay Kumar40252eb2025-10-13 13:25:53 +000011// import (
12// "testing"
13// "github.com/stretchr/testify/assert"
14// )
Scott Baker2c1c4822019-10-16 11:02:41 -070015//
Abhay Kumar40252eb2025-10-13 13:25:53 +000016// func TestSomething(t *testing.T) {
Scott Baker2c1c4822019-10-16 11:02:41 -070017//
Abhay Kumar40252eb2025-10-13 13:25:53 +000018// var a string = "Hello"
19// var b string = "Hello"
Scott Baker2c1c4822019-10-16 11:02:41 -070020//
Abhay Kumar40252eb2025-10-13 13:25:53 +000021// assert.Equal(t, a, b, "The two words should be the same.")
22//
23// }
Scott Baker2c1c4822019-10-16 11:02:41 -070024//
25// if you assert many times, use the format below:
26//
Abhay Kumar40252eb2025-10-13 13:25:53 +000027// import (
28// "testing"
29// "github.com/stretchr/testify/assert"
30// )
Scott Baker2c1c4822019-10-16 11:02:41 -070031//
Abhay Kumar40252eb2025-10-13 13:25:53 +000032// func TestSomething(t *testing.T) {
33// assert := assert.New(t)
Scott Baker2c1c4822019-10-16 11:02:41 -070034//
Abhay Kumar40252eb2025-10-13 13:25:53 +000035// var a string = "Hello"
36// var b string = "Hello"
Scott Baker2c1c4822019-10-16 11:02:41 -070037//
Abhay Kumar40252eb2025-10-13 13:25:53 +000038// assert.Equal(a, b, "The two words should be the same.")
39// }
Scott Baker2c1c4822019-10-16 11:02:41 -070040//
Abhay Kumar40252eb2025-10-13 13:25:53 +000041// # Assertions
Scott Baker2c1c4822019-10-16 11:02:41 -070042//
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