blob: c8e3f94a8034a8b7968d7b09d3b21b3119b1fd10 [file] [log] [blame]
amit.ghosh6ab2a982022-09-15 21:04:53 +02001// Package require implements the same assertions as the `assert` package but
2// stops test execution when a test fails.
3//
Abhay Kumar40252eb2025-10-13 13:25:53 +00004// # Example Usage
amit.ghosh6ab2a982022-09-15 21:04:53 +02005//
6// The following is a complete example using require in a standard test function:
amit.ghosh6ab2a982022-09-15 21:04:53 +02007//
Abhay Kumar40252eb2025-10-13 13:25:53 +00008// import (
9// "testing"
10// "github.com/stretchr/testify/require"
11// )
amit.ghosh6ab2a982022-09-15 21:04:53 +020012//
Abhay Kumar40252eb2025-10-13 13:25:53 +000013// func TestSomething(t *testing.T) {
amit.ghosh6ab2a982022-09-15 21:04:53 +020014//
Abhay Kumar40252eb2025-10-13 13:25:53 +000015// var a string = "Hello"
16// var b string = "Hello"
amit.ghosh6ab2a982022-09-15 21:04:53 +020017//
Abhay Kumar40252eb2025-10-13 13:25:53 +000018// require.Equal(t, a, b, "The two words should be the same.")
amit.ghosh6ab2a982022-09-15 21:04:53 +020019//
Abhay Kumar40252eb2025-10-13 13:25:53 +000020// }
21//
22// # Assertions
amit.ghosh6ab2a982022-09-15 21:04:53 +020023//
24// The `require` package have same global functions as in the `assert` package,
25// but instead of returning a boolean result they call `t.FailNow()`.
Abhay Kumar40252eb2025-10-13 13:25:53 +000026// A consequence of this is that it must be called from the goroutine running
27// the test function, not from other goroutines created during the test.
amit.ghosh6ab2a982022-09-15 21:04:53 +020028//
29// Every assertion function also takes an optional string message as the final argument,
30// allowing custom error messages to be appended to the message the assertion method outputs.
31package require