blob: a0b953aa5cf60d46e68b7cc24c8607f123d26e96 [file] [log] [blame]
Holger Hildebrandtda7758b2020-03-16 11:30:03 +00001// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
2//
Abhay Kumare65b2792025-11-10 13:39:07 +00003// # Note
4//
5// All functions in this package return a bool value indicating whether the assertion has passed.
6//
7// # Example Usage
Holger Hildebrandtda7758b2020-03-16 11:30:03 +00008//
9// The following is a complete example using assert in a standard test function:
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000010//
Abhay Kumare65b2792025-11-10 13:39:07 +000011// import (
12// "testing"
13// "github.com/stretchr/testify/assert"
14// )
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000015//
Abhay Kumare65b2792025-11-10 13:39:07 +000016// func TestSomething(t *testing.T) {
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000017//
Abhay Kumare65b2792025-11-10 13:39:07 +000018// var a string = "Hello"
19// var b string = "Hello"
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000020//
Abhay Kumare65b2792025-11-10 13:39:07 +000021// assert.Equal(t, a, b, "The two words should be the same.")
22//
23// }
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000024//
25// if you assert many times, use the format below:
26//
Abhay Kumare65b2792025-11-10 13:39:07 +000027// import (
28// "testing"
29// "github.com/stretchr/testify/assert"
30// )
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000031//
Abhay Kumare65b2792025-11-10 13:39:07 +000032// func TestSomething(t *testing.T) {
33// assert := assert.New(t)
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000034//
Abhay Kumare65b2792025-11-10 13:39:07 +000035// var a string = "Hello"
36// var b string = "Hello"
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000037//
Abhay Kumare65b2792025-11-10 13:39:07 +000038// assert.Equal(a, b, "The two words should be the same.")
39// }
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000040//
Abhay Kumare65b2792025-11-10 13:39:07 +000041// # Assertions
Holger Hildebrandtda7758b2020-03-16 11:30:03 +000042//
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