2021-08-12 21:03:24 +02:00
|
|
|
// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
|
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// # Example Usage
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
|
|
|
// The following is a complete example using assert in a standard test function:
|
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// import (
|
|
|
|
// "testing"
|
|
|
|
// "github.com/stretchr/testify/assert"
|
|
|
|
// )
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// func TestSomething(t *testing.T) {
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// var a string = "Hello"
|
|
|
|
// var b string = "Hello"
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// assert.Equal(t, a, b, "The two words should be the same.")
|
|
|
|
//
|
|
|
|
// }
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
|
|
|
// if you assert many times, use the format below:
|
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// import (
|
|
|
|
// "testing"
|
|
|
|
// "github.com/stretchr/testify/assert"
|
|
|
|
// )
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// func TestSomething(t *testing.T) {
|
|
|
|
// assert := assert.New(t)
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// var a string = "Hello"
|
|
|
|
// var b string = "Hello"
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// assert.Equal(a, b, "The two words should be the same.")
|
|
|
|
// }
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
2023-05-29 14:47:57 +02:00
|
|
|
// # Assertions
|
2021-08-12 21:03:24 +02:00
|
|
|
//
|
|
|
|
// Assertions allow you to easily write test code, and are global funcs in the `assert` package.
|
|
|
|
// All assertion functions take, as the first argument, the `*testing.T` object provided by the
|
|
|
|
// testing framework. This allows the assertion funcs to write the failings and other details to
|
|
|
|
// the correct place.
|
|
|
|
//
|
|
|
|
// Every assertion function also takes an optional string message as the final argument,
|
|
|
|
// allowing custom error messages to be appended to the message the assertion method outputs.
|
|
|
|
package assert
|