| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. |
| 2 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 3 | // # Note |
| 4 | // |
| 5 | // All functions in this package return a bool value indicating whether the assertion has passed. |
| 6 | // |
| 7 | // # Example Usage |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 8 | // |
| 9 | // The following is a complete example using assert in a standard test function: |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 10 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 11 | // import ( |
| 12 | // "testing" |
| 13 | // "github.com/stretchr/testify/assert" |
| 14 | // ) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 15 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 16 | // func TestSomething(t *testing.T) { |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 17 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 18 | // var a string = "Hello" |
| 19 | // var b string = "Hello" |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 20 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 21 | // assert.Equal(t, a, b, "The two words should be the same.") |
| 22 | // |
| 23 | // } |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 24 | // |
| 25 | // if you assert many times, use the format below: |
| 26 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 27 | // import ( |
| 28 | // "testing" |
| 29 | // "github.com/stretchr/testify/assert" |
| 30 | // ) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 31 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 32 | // func TestSomething(t *testing.T) { |
| 33 | // assert := assert.New(t) |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 34 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 35 | // var a string = "Hello" |
| 36 | // var b string = "Hello" |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 37 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 38 | // assert.Equal(a, b, "The two words should be the same.") |
| 39 | // } |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 40 | // |
| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 41 | // # Assertions |
| Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 42 | // |
| 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. |
| 50 | package assert |