blob: a0b953aa5cf60d46e68b7cc24c8607f123d26e96 [file] [log] [blame]
kesavandb9f54fd2021-11-25 20:08:04 +05301// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
2//
Abhay Kumara61c5222025-11-10 07:32:50 +00003// # Note
4//
5// All functions in this package return a bool value indicating whether the assertion has passed.
6//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +05307// # Example Usage
kesavandb9f54fd2021-11-25 20:08:04 +05308//
9// The following is a complete example using assert in a standard test function:
kesavandb9f54fd2021-11-25 20:08:04 +053010//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +053011// import (
12// "testing"
13// "github.com/stretchr/testify/assert"
14// )
kesavandb9f54fd2021-11-25 20:08:04 +053015//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +053016// func TestSomething(t *testing.T) {
kesavandb9f54fd2021-11-25 20:08:04 +053017//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +053018// var a string = "Hello"
19// var b string = "Hello"
kesavandb9f54fd2021-11-25 20:08:04 +053020//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +053021// assert.Equal(t, a, b, "The two words should be the same.")
22//
23// }
kesavandb9f54fd2021-11-25 20:08:04 +053024//
25// if you assert many times, use the format below:
26//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +053027// import (
28// "testing"
29// "github.com/stretchr/testify/assert"
30// )
kesavandb9f54fd2021-11-25 20:08:04 +053031//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +053032// func TestSomething(t *testing.T) {
33// assert := assert.New(t)
kesavandb9f54fd2021-11-25 20:08:04 +053034//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +053035// var a string = "Hello"
36// var b string = "Hello"
kesavandb9f54fd2021-11-25 20:08:04 +053037//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +053038// assert.Equal(a, b, "The two words should be the same.")
39// }
kesavandb9f54fd2021-11-25 20:08:04 +053040//
Akash Reddy Kankanalad9ec4822025-06-10 22:59:53 +053041// # Assertions
kesavandb9f54fd2021-11-25 20:08:04 +053042//
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