blob: a0b953aa5cf60d46e68b7cc24c8607f123d26e96 [file] [log] [blame]
vinokumaf7605fc2023-06-02 18:08:01 +05301// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
2//
Abhay Kumarfe505f22025-11-10 14:16:31 +00003// # Note
4//
5// All functions in this package return a bool value indicating whether the assertion has passed.
6//
7// # Example Usage
vinokumaf7605fc2023-06-02 18:08:01 +05308//
9// The following is a complete example using assert in a standard test function:
vinokumaf7605fc2023-06-02 18:08:01 +053010//
Abhay Kumarfe505f22025-11-10 14:16:31 +000011// import (
12// "testing"
13// "github.com/stretchr/testify/assert"
14// )
vinokumaf7605fc2023-06-02 18:08:01 +053015//
Abhay Kumarfe505f22025-11-10 14:16:31 +000016// func TestSomething(t *testing.T) {
vinokumaf7605fc2023-06-02 18:08:01 +053017//
Abhay Kumarfe505f22025-11-10 14:16:31 +000018// var a string = "Hello"
19// var b string = "Hello"
vinokumaf7605fc2023-06-02 18:08:01 +053020//
Abhay Kumarfe505f22025-11-10 14:16:31 +000021// assert.Equal(t, a, b, "The two words should be the same.")
22//
23// }
vinokumaf7605fc2023-06-02 18:08:01 +053024//
25// if you assert many times, use the format below:
26//
Abhay Kumarfe505f22025-11-10 14:16:31 +000027// import (
28// "testing"
29// "github.com/stretchr/testify/assert"
30// )
vinokumaf7605fc2023-06-02 18:08:01 +053031//
Abhay Kumarfe505f22025-11-10 14:16:31 +000032// func TestSomething(t *testing.T) {
33// assert := assert.New(t)
vinokumaf7605fc2023-06-02 18:08:01 +053034//
Abhay Kumarfe505f22025-11-10 14:16:31 +000035// var a string = "Hello"
36// var b string = "Hello"
vinokumaf7605fc2023-06-02 18:08:01 +053037//
Abhay Kumarfe505f22025-11-10 14:16:31 +000038// assert.Equal(a, b, "The two words should be the same.")
39// }
vinokumaf7605fc2023-06-02 18:08:01 +053040//
Abhay Kumarfe505f22025-11-10 14:16:31 +000041// # Assertions
vinokumaf7605fc2023-06-02 18:08:01 +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