assert

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 6 Imported by: 0

README

Assertion for Golang

test Go Report Card codecov Version Badge License Badge Go Reference

A collection of Golang assertion functions for verifying invariants.

Installation

To install this library, just use go get command like the following line:

go get -u github.com/ghosind/go-assert

Getting Started

This library provided assertion functions to verify the equality of values, or assert for nil:

func TestExample(t *testing.T) {
  // var actual
  // var expect

  // assert equality
  assert.Equal(t, actual, expect)

  // assert inequality
  assert.NotEqual(t, actual, expect)

  // you can also use DeepEqual to assert the equality that also checks the type between the values
  assert.DeepEqual(t, actual, expect)

  // var object

  // assert for nil
  assert.Nil(t, object)

  // assert for not nil
  assert.NotNil(t, object)
}

You can use True method to check whether a value is truthy or falsy (is the zero value of the type or not).

func TestExample(t *testing.T) {
  assert.True(t, 1) // success
  assert.True(t, 0) // fail
  assert.True(t, "test") // success
  assert.True(t, "") // fail
}

If you want to test the value of a string, you can use Match method to test it with a regular expression pattern.

func TestExample(t *testing.T) {
  pattern := regexp.MustCompile(`^https?:\/\/`)
  assert.Match(t, "https://example.com", pattern) // success
  assert.Match(t, "example.com", pattern) // fail

  // you can also use `MatchString` to test it without compiling the regexp pattern
  assert.MatchString(t, "https://example.com", `^https?:\/\/`) // success
}

Since v0.2.0, we also provided some assertions for array/slice, for example, you can use ContainsElement to check whether an array or a slice contains a specified element.

func TestExample(t *testing.T) {
  arr := []int{1, 2, 3}
  assert.ContainsElement(arr, 1) // success
  assert.ContainsElement(arr, 4) // fail
}

It also provided assertion functions to verify a function will panic or not:

func TestPanic(t *testing.T) {
  // assert panic
  assert.Panic(t, func () {
    // do something

    panic()
  })

  // assert no panic
  assert.NotPanic(t, func () {
    // do something

    // panic()
  })
}

For every assertion functions, it also provided XXXNow functions to stop the execution if the test is failed.

func TestExample(t *testing.T) {
  // var actual
  // var expect

  // The following line will set the test result to fail and stop the execution
  assert.EqualNow(t, actual, expect)

  // The following lines will never execute if they are not equal.
  // ...
}

Every assertion will not terminate the testing workflow. However, they'll return an error if the verification failed, and you can check the return value to get the verification result.

func TestExample(t *testing.T) {
  if err := assert.Equal(t, actual, expect); err != nil {
    // terminate test
    t.Fail()
  }
}

If you need to assert many times, you can also create an Assertion instance:

func TestExample(t *testing.T) {
  assertion := assert.New(t)

  // test equality
  assertion.Equal(actual, expect)

  // Test inequality
  assertion.NotEqual(actual, expect)
}

Available Assertions

Equality
Comparison
  • Gt: assert the first value is greater than the second value.

    Since v1.0.0

  • Gte: assert the first value is greater than or equal to the second value.

    Since v1.0.0

  • Lt: assert the first value is less than the second value.

    Since v1.0.0

  • Lte: assert the first value is less than or equal to the second value.

    Since v1.0.0

Value
  • Nil and NotNil: assert the value is nil or not.

    Since v0.1.1

  • True and NotTrue: assert the truthy of the value.

    Since v0.1.4

String
Slice or Array
Map
Error Handling
  • IsError and NotIsError: assert the error matches the target error or not.

    Since v1.1.0

  • Panic and NotPanic: assert the function will panic or not.

    Since v0.1.0

  • PanicOf: assert the function will panic by the expected error.

    Since v0.1.0

  • NotPanicOf: assert the function will not panic, or it will panic but it is not by the unexpected error.

Since v0.1.0

Custom Error Message

You can customize the error message if you don't like the default message. Every assertion function accepts an optional message arguments list, and the first argument is the argument is the format string of the custom message.

actual := 1
expect := 2
assert.Equal(actual, expect)
// assert error: 1 != 2

assert.Equal(actual, expect, "unexpected result")
// unexpected result

assert.Equal(actual, expect, "actual = %v, expect = %v", actual, expect)
// actual = 1, expect = 2

For custom error messages, the first argument of messages must be the format string, it'll fall back to the default error message if not a string.

License

This project was published under the MIT license, you can see LICENSE file to get more information.

Documentation

Overview

Package assert implements assertion functions for verifying invariants to extend the built-in testing package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotArray indicates that the value must be a slice or an array.
	ErrNotArray error = errors.New("the value must be a slice or an array")
	// ErrNotFloat indicates that the value must be a floating number.
	ErrNotFloat error = errors.New("the value must be a floating number")
	// ErrNotMap indicates that the value must be a map.
	ErrNotMap error = errors.New("the value must be a map")
	// ErrNotOrderable indicates that the value must be orderable.
	ErrNotOrderable error = errors.New("the value must be orderable")
	// ErrNotSameType indicates that both values must be the same type.
	ErrNotSameType error = errors.New("the values must be the same type")
	// ErrRequireT indicates that the instance of testing.T is a required parameter.
	ErrRequireT error = errors.New("testing.T is required")
)

Functions

func ContainsElement added in v0.2.0

func ContainsElement(t *testing.T, source, expect any, message ...any) error

NotContainsElement tests whether the array or slice contains the specified element or not, and it set the result to fail if the array or slice does not contain the specified element. It'll panic if the `source` is not an array or a slice.

assert.ContainsElement(t, []int{1, 2, 3}, 1) // success
assert.ContainsElement(t, []int{1, 2, 3}, 3) // success
assert.ContainsElement(t, []int{1, 2, 3}, 4) // fail

func ContainsElementNow added in v0.2.0

func ContainsElementNow(t *testing.T, source, expect any, message ...any) error

ContainsElementNow tests whether the array or slice contains the specified element or not, and it will terminate the execution if the array or slice does not contain the specified element. It'll panic if the `source` is not an array or a slice.

assert.ContainsElementNow(t, []int{1, 2, 3}, 1) // success
assert.ContainsElementNow(t, []int{1, 2, 3}, 3) // success
assert.ContainsElementNow(t, []int{1, 2, 3}, 4) // fail and stop the execution
// never runs

func ContainsString added in v0.1.7

func ContainsString(t *testing.T, str, substr string, message ...any) error

ContainsString tests whether the string contains the substring or not, and it set the result to fail if the string does not contains the substring.

assert.ContainsString(t, "Hello world", "") // success
assert.ContainsString(t, "Hello world", "Hello") // success
assert.ContainsString(t, "Hello world", "world") // success
assert.ContainsString(t, "Hello world", "hello") // fail

func ContainsStringNow added in v0.1.7

func ContainsStringNow(t *testing.T, str, substr string, message ...any) error

ContainsStringNow tests whether the string contains the substring or not, and it will terminate the execution if the string does not contains the substring.

assert.ContainsStringNow(t, "Hello world", "") // success
assert.ContainsStringNow(t, "Hello world", "Hello") // success
assert.ContainsStringNow(t, "Hello world", "world") // success
assert.ContainsStringNow(t, "Hello world", "hello") // fail and stop the execution
// never runs

func DeepEqual

func DeepEqual(t *testing.T, actual, expect any, message ...any) error

DeepEqual tests the deep equality between actual and expect parameters. It'll set the result to fail if they are not deeply equal, and it doesn't stop the execution.

assert.DeepEqual(t, 1, 1) // success
assert.DeepEqual(t, "ABC", "ABC") // success
assert.DeepEqual(t, 1, 0) // fail
assert.DeepEqual(t, 1, int64(1)) // fail

func DeepEqualNow added in v0.1.2

func DeepEqualNow(t *testing.T, actual, expect any, message ...any) error

DeepEqualNow tests the deep equality between actual and expect parameters, and it'll stop the execution if they are not deeply equal.

assert.DeepEqualNow(t, 1, 1) // success
assert.DeepEqualNow(t, "ABC", "ABC") // success
assert.DeepEqualNow(t, 1, int64(1)) // fail and terminate
// never run

func Equal added in v0.1.5

func Equal(t *testing.T, actual, expect any, message ...any) error

Equal tests the equality between actual and expect parameters. It'll set the result to fail if they are not equal, and it doesn't stop the execution.

assert.Equal(t, 1, 1) // success
assert.Equal(t, "ABC", "ABC") // success
assert.Equal(t, 1, int64(1)) // success
assert.Equal(t, 1, uint64(1)) // fail
assert.Equal(t, 1, 0) // fail

func EqualNow added in v0.1.5

func EqualNow(t *testing.T, actual, expect any, message ...any) error

EqualNow tests the equality between actual and expect parameters, and it'll stop the execution if they are not equal.

assert.EqualNow(t, 1, 1) // success
assert.EqualNow(t, "ABC", "ABC") // success
assert.EqualNow(t, 1, int64(1)) // success
assert.EqualNow(t, 1, 0) // fail and terminate
never run

func FloatEqual added in v1.1.1

func FloatEqual(t *testing.T, actual, expect, epsilon any, message ...any) error

FloatEqual tests the equality between actual and expect floating numbers with epsilon. It'll set the result to fail if they are not equal, and it doesn't stop the execution.

FloatEqual(t, 1.0, 1.0, 0.1) // success
FloatEqual(t, 1.0, 1.01, 0.1) // success
FloatEqual(t, 1.0, 1.2, 0.1) // fail

func FloatEqualNow added in v1.1.1

func FloatEqualNow(t *testing.T, actual, expect, epsilon any, message ...any) error

FloatEqualNow tests the equality between actual and expect floating numbers with epsilon, and it'll stop the execution if they are not equal.

FloatEqualNow(t, 1.0, 1.0, 0.1) // success
FloatEqualNow(t, 1.0, 1.01, 0.1) // success
FloatEqualNow(t, 1.0, 1.2, 0.1) // fail and terminate

func FloatNotEqual added in v1.1.1

func FloatNotEqual(t *testing.T, actual, expect, epsilon any, message ...any) error

FloatNotEqual tests the inequality between actual and expect floating numbers with epsilon. It'll set the result to fail if they are equal, but it doesn't stop the execution.

FloatNotEqual(t, 1.0, 1.2, 0.1) // success
FloatNotEqual(t, 1.0, 1.1, 0.1) // success
FloatNotEqual(t, 1.0, 1.0, 0.1) // fail

func FloatNotEqualNow added in v1.1.1

func FloatNotEqualNow(t *testing.T, actual, expect, epsilon any, message ...any) error

FloatNotEqualNow tests the inequality between actual and expect floating numbers with epsilon, and it'll stop the execution if they are equal.

FloatNotEqualNow(t, 1.0, 1.2, 0.1) // success
FloatNotEqualNow(t, 1.0, 1.1, 0.1) // success
FloatNotEqualNow(t, 1.0, 1.0, 0.1) // fail and terminate

func Gt added in v1.0.0

func Gt(t *testing.T, v1, v2 any, message ...string) error

Gt compares the values and sets the result to false if the first value is not greater than to the second value.

assert.Gt(t, 2, 1) // success
assert.Gt(t, 3.14, 1.68) // success
assert.Gt(t, "BCD", "ABC") // success
assert.Gt(t, 2, 2) // fail
assert.Gt(t, 1, 2) // fail

func GtNow added in v1.0.0

func GtNow(t *testing.T, v1, v2 any, message ...string) error

GtNow compares the values and sets the result to false if the first value is not greater than to the second value. It will panic if they do not match the expected result.

assert.GtNow(t, 2, 1) // success
assert.GtNow(t, 3.14, 1.68) // success
assert.GtNow(t, "BCD", "ABC") // success
assert.GtNow(t, 1, 2) // fail and terminate
// never runs

func Gte added in v1.0.0

func Gte(t *testing.T, v1, v2 any, message ...string) error

Gte compares the values and sets the result to false if the first value is not greater than or equal to the second value.

assert.Gte(t, 2, 1) // success
assert.Gte(t, 3.14, 1.68) // success
assert.Gte(t, "BCD", "ABC") // success
assert.Gte(t, 2, 2) // success
assert.Gte(t, 1, 2) // fail

func GteNow added in v1.0.0

func GteNow(t *testing.T, v1, v2 any, message ...string) error

GteNow compares the values and sets the result to false if the first value is not greater than or equal to the second value. It will panic if they do not match the expected result.

assert.GteNow(t, 2, 1) // success
assert.GteNow(t, 3.14, 1.68) // success
assert.GteNow(t, "BCD", "ABC") // success
assert.GteNow(t, 2, 2) // success
assert.GteNow(t, 1, 2) // fail and terminate
// never runs

func HasPrefixString added in v0.1.7

func HasPrefixString(t *testing.T, str, prefix string, message ...any) error

HasPrefixString tests whether the string has the prefix string or not, and it set the result to fail if the string does not have the prefix string.

assert.HasPrefixString(t, "Hello world", "") // success
assert.HasPrefixString(t, "Hello world", "Hello") // success
assert.HasPrefixString(t, "Hello world", "world") // fail
assert.HasPrefixString(t, "Hello world", "hello") // fail

func HasPrefixStringNow added in v0.1.7

func HasPrefixStringNow(t *testing.T, str, prefix string, message ...any) error

HasPrefixStringNow tests whether the string has the prefix string or not, and it will terminate the execution if the string does not have the prefix string.

assert.HasPrefixStringNow(t, "Hello world", "") // success
assert.HasPrefixStringNow(t, "Hello world", "Hello") // success
assert.HasPrefixStringNow(t, "Hello world", "hello") // fail and stop the execution
// never runs

func HasSuffixString added in v0.1.7

func HasSuffixString(t *testing.T, str, suffix string, message ...any) error

HasSuffixString tests whether the string has the suffix string or not, and it set the result to fail if the string does not have the suffix string.

assert.HasSuffixString(t, "Hello world", "") // success
assert.HasSuffixString(t, "Hello world", "world") // success
assert.HasSuffixString(t, "Hello world", "World") // fail
assert.HasSuffixString(t, "Hello world", "hello") // fail

func HasSuffixStringNow added in v0.1.7

func HasSuffixStringNow(t *testing.T, str, suffix string, message ...any) error

HasSuffixStringNow tests whether the string has the suffix string or not, and it will terminate the execution if the string does not have the suffix string.

assert.HasSuffixStringNow(t, "Hello world", "") // success
assert.HasSuffixStringNow(t, "Hello world", "world") // success
assert.HasSuffixStringNow(t, "Hello world", "World") // fail and stop the execution
// never runs

func IsError added in v1.1.0

func IsError(t *testing.T, err, expected error, message ...any) error

IsError tests whether the error matches the target or not. It'll set the result to fail if the error does not match to the target error, and it doesn't stop the execution.

err1 := errors.New("error 1")
err2 := errors.New("error 2")
err3 := errors.New("error 3")
assert.IsError(t, err1, err1) // success
assert.IsError(t, err1, err2) // fail
assert.IsError(t, errors.Join(err1, err2), err1) // success
assert.IsError(t, errors.Join(err1, err2), err2) // success
assert.IsError(t, errors.Join(err1, err2), err3) // fail

func IsErrorNow added in v1.1.0

func IsErrorNow(t *testing.T, err, expected error, message ...any) error

IsErrorNow tests whether the error matches the target or not. It'll set the result to fail and stop the execution if the error does not match to the target error.

err1 := errors.New("error 1")
err2 := errors.New("error 2")
assert.IsErrorNow(t, errors.Join(err1, err2), err1) // success
assert.IsErrorNow(t, errors.Join(err1, err2), err2) // success
assert.IsErrorNow(t, err1, err1) // success
assert.IsErrorNow(t, err1, err2) // fail
// never runs

func Lt added in v1.0.0

func Lt(t *testing.T, v1, v2 any, message ...string) error

Lt compares the values and sets the result to false if the first value is not less than the second value.

assert.Lt(t, 1, 2) // success
assert.Lt(t, 1.68, 3.14) // success
assert.Lt(t, "ABC", "BCD") // success
assert.Lt(t, 2, 2) // fail
assert.Lt(t, 2, 1) // fail

func LtNow added in v1.0.0

func LtNow(t *testing.T, v1, v2 any, message ...string) error

LtNow compares the values and sets the result to false if the first value is not less than the second value. It will panic if they do not match the expected result.

assert.LtNow(t, 1, 2) // success
assert.LtNow(t, 1.68, 3.14) // success
assert.LtNow(t, "ABC", "BCD") // success
assert.LtNow(t, 2, 1) // fail and terminate
// never runs

func Lte added in v1.0.0

func Lte(t *testing.T, v1, v2 any, message ...string) error

Lte compares the values and sets the result to false if the first value is not less than or equal to the second value.

assert.Lte(t, 1, 2) // success
assert.Lte(t, 1.68, 3.14) // success
assert.Lte(t, "ABC", "BCD") // success
assert.Lte(t, 2, 2) // success
assert.Lte(t, 2, 1) // fail

func LteNow added in v1.0.0

func LteNow(t *testing.T, v1, v2 any, message ...string) error

LteNow compares the values and sets the result to false if the first value is not less than or equal to the second value. It will panic if they do not match the expected result.

assert.LteNow(t, 1, 2) // success
assert.LteNow(t, 1.68, 3.14) // success
assert.LteNow(t, "ABC", "BCD") // success
assert.LteNow(t, 2, 2) // success
assert.LteNow(t, 2, 1) // fail and terminate
// never runs

func MapHasKey added in v0.2.1

func MapHasKey(t *testing.T, m, key any, message ...any) error

MapHasKey tests whether the map contains the specified key or not, it will fail if the map does not contain the key, or the type of the key cannot assign to the type of the key of the map.

assert.MapHasKey(t, map[string]int{"a":1}, "a") // success
assert.MapHasKey(t, map[string]int{"a":1}, "b") // fail
assert.MapHasKey(t, map[string]int{"a":1}, 1) // fail

func MapHasKeyNow added in v0.2.1

func MapHasKeyNow(t *testing.T, m, key any, message ...any) error

MapHasKeyNow tests whether the map contains the specified key or not, and it will terminate the execution if the test fails. It will fail if the map does not contain the key, or the type of the key cannot assign to the type of the key of the map.

assert.MapHasKeyNow(t, map[string]int{"a":1}, "a") // success
assert.MapHasKeyNow(t, map[string]int{"a":1}, "b") // fail and terminate
// never run

func MapHasValue added in v0.2.1

func MapHasValue(t *testing.T, m, value any, message ...any) error

MapHasValue tests whether the map contains the specified value or not, it will fail if the map does not contain the value, or the type of the value cannot assign to the type of the values of the map.

assert.MapHasValue(t, map[string]int{"a":1}, 1) // success
assert.MapHasValue(t, map[string]int{"a":1}, 2) // fail
assert.MapHasValue(t, map[string]int{"a":1}, "a") // fail

func MapHasValueNow added in v0.2.1

func MapHasValueNow(t *testing.T, m, value any, message ...any) error

MapHasValueNow tests whether the map contains the specified value or not, and it will terminate the execution if the test fails. It will fail if the map does not contain the value, or the type of the value cannot assign to the type of the value of the map.

assert.MapHasValueNow(t, map[string]int{"a":1}, 1) // success
assert.MapHasValueNow(t, map[string]int{"a":1}, 2) // fail and terminate
// never run

func Match added in v0.1.5

func Match(t *testing.T, val string, pattern *regexp.Regexp, message ...any) error

Match tests whether the string matches the regular expression or not.

pattern := regexp.MustCompile(`^https?:\/\/`)
assert.Match(t, "http://example.com", pattern) // success
assert.Match(t, "example.com", pattern) // fail

func MatchNow added in v0.1.5

func MatchNow(t *testing.T, val string, pattern *regexp.Regexp, message ...any) error

MatchNow tests whether the string matches the regular expression or not, and it will terminate the execution if it does not match.

pattern := regexp.MustCompile(`^https?:\/\/`)
assert.MatchNow(t, "http://example.com", pattern) // success
assert.MatchNow(t, "example.com", pattern) // fail and terminate
// never run

func MatchString added in v0.1.5

func MatchString(t *testing.T, val, pattern string, message ...any) error

MatchString will compile the pattern and test whether the string matches the regular expression or not. It will panic if the pattern is not a valid regular expression.

assert.MatchString(t, "http://example.com", `^https?:\/\/`) // success
assert.MatchString(t, "example.com", `^https?:\/\/`) // fail

func MatchStringNow added in v0.1.5

func MatchStringNow(t *testing.T, val, pattern string, message ...any) error

MatchStringNow will compile the pattern and test whether the string matches the regular expression or not. It will terminate the execution if it does not match, and it will panic if the pattern is not a valid regular expression.

assert.MatchStringNow(t, "http://example.com", `^https?:\/\/`) // success
assert.MatchStringNow(t, "example.com", `^https?:\/\/`) // fail and terminate
// never run

func Nil added in v0.1.1

func Nil(t *testing.T, val any, message ...any) error

Nil tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.

var err error // nil
assert.Nil(t, err) // success

err = errors.New("some error")
assert.Nil(t, err) // fail

func NilNow added in v0.1.2

func NilNow(t *testing.T, val any, message ...any) error

NilNow tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.

This function will set the result to fail, and stop the execution if the value is not nil.

var err error // nil
assert.NilNow(t, err) // success

err = errors.New("some error")
assert.NilNow(t, err) // fail and terminate
// never run

func NotContainsElement added in v0.2.0

func NotContainsElement(t *testing.T, source, expect any, message ...any) error

NotContainsElement tests whether the array or slice contains the specified element or not, and it set the result to fail if the array or slice contains the specified element. It'll panic if the `source` is not an array or a slice.

assert.NotContainsElement(t, []int{1, 2, 3}, 4) // success
assert.NotContainsElement(t, []int{1, 2, 3}, 0) // success
assert.NotContainsElement(t, []int{1, 2, 3}, 1) // fail

func NotContainsElementNow added in v0.2.0

func NotContainsElementNow(t *testing.T, source, expect any, message ...any) error

NotContainsElementNow tests whether the array or slice contains the specified element or not, and it will terminate the execution if the array or slice contains the specified element. It'll panic if the `source` is not an array or a slice.

assert.NotContainsElementNow(t, []int{1, 2, 3}, 4) // success
assert.NotContainsElementNow(t, []int{1, 2, 3}, 0) // success
assert.NotContainsElementNow(t, []int{1, 2, 3}, 1) // fail and stop the execution
// never runs

func NotContainsString added in v0.1.7

func NotContainsString(t *testing.T, str, substr string, message ...any) error

NotContainsString tests whether the string contains the substring or not, and it set the result to fail if the string contains the substring.

assert.NotContainsString(t, "Hello world", "") // fail
assert.NotContainsString(t, "Hello world", "Hello") // fail
assert.NotContainsString(t, "Hello world", "world") // fail
assert.NotContainsString(t, "Hello world", "hello") // success

func NotContainsStringNow added in v0.1.7

func NotContainsStringNow(t *testing.T, str, substr string, message ...any) error

NotContainsStringNow tests whether the string contains the substring or not, and it will terminate the execution if the string contains the substring.

assert.NotContainsStringNow(t, "Hello world", "hello") // success
assert.NotContainsStringNow(t, "Hello world", "Hello") // fail and stop the execution
// never runs

func NotDeepEqual

func NotDeepEqual(t *testing.T, actual, expect any, message ...any) error

NotDeepEqual tests the deep inequality between actual and expected parameters. It'll set the result to fail if they are deeply equal, but it doesn't stop the execution.

assert.NotDeepEqual(t, 1, 0) // success
assert.NotDeepEqual(t, 1, int64(1)) // success
assert.NotDeepEqual(t, 1, 1) // fail
assert.NotDeepEqual(t, "ABC", "ABC") // fail

func NotDeepEqualNow added in v0.1.2

func NotDeepEqualNow(t *testing.T, actual, expect any, message ...any) error

NotDeepEqualNow tests the deep inequality between actual and expected parameters, and it'll stop the execution if they are deeply equal.

assert.NotDeepEqual(t, 1, 0) // success
assert.NotDeepEqual(t, 1, int64(1)) // success
assert.NotDeepEqual(t, "ABC", "ABC") // fail and terminate
// never run

func NotEqual added in v0.1.5

func NotEqual(t *testing.T, actual, expect any, message ...any) error

NotEqual tests the inequality between actual and expected parameters. It'll set the result to fail if they are equal, but it doesn't stop the execution.

assert.NotEqual(t, 1, 0) // success
assert.NotEqual(t, "ABC", "CBA") // success
assert.NotEqual(t, 1, uint64(1)) // success
assert.NotEqual(t, 1, 1) // fail
assert.NotEqual(t, "ABC", "ABC") // fail
assert.NotEqual(t, 1, int64(1)) // fail

func NotEqualNow added in v0.1.5

func NotEqualNow(t *testing.T, actual, expect any, message ...any) error

NotEqualNow tests the inequality between actual and expected parameters, and it'll stop the execution if they are equal.

assert.NotEqualNow(t, 1, 0) // success
assert.NotEqualNow(t, "ABC", "CBA") // success
assert.NotEqualNow(t, 1, 1) // fail and terminate
// never run

func NotHasPrefixString added in v0.1.7

func NotHasPrefixString(t *testing.T, str, prefix string, message ...any) error

NotHasPrefixString tests whether the string has the prefix string or not, and it set the result to fail if the string have the prefix string.

assert.NotHasPrefixString(t, "Hello world", "hello") // success
assert.NotHasPrefixString(t, "Hello world", "world") // success
assert.NotHasPrefixString(t, "Hello world", "") // fail
assert.NotHasPrefixString(t, "Hello world", "Hello") // fail

func NotHasPrefixStringNow added in v0.1.7

func NotHasPrefixStringNow(t *testing.T, str, prefix string, message ...any) error

NotHasPrefixStringNow tests whether the string has the prefix string or not, and it will terminate the execution if the string have the prefix string.

assert.NotHasPrefixStringNow(t, "Hello world", "hello") // success
assert.NotHasPrefixStringNow(t, "Hello world", "world") // success
assert.NotHasPrefixStringNow(t, "Hello world", "Hello") // fail and stop the execution
// never runs

func NotHasSuffixString added in v0.1.7

func NotHasSuffixString(t *testing.T, str, suffix string, message ...any) error

NotHasSuffixString tests whether the string has the suffix string or not, and it set the result to fail if the string have the suffix string.

assert.NotHasSuffixString(t, "Hello world", "Hello") // success
assert.NotHasSuffixString(t, "Hello world", "World") // success
assert.NotHasSuffixString(t, "Hello world", "") // fail
assert.NotHasSuffixString(t, "Hello world", "world") // fail

func NotHasSuffixStringNow added in v0.1.7

func NotHasSuffixStringNow(t *testing.T, str, suffix string, message ...any) error

NotHasSuffixStringNow tests whether the string has the suffix string or not, and it will terminate the execution if the string have the suffix string.

assert.NotHasSuffixStringNow(t, "Hello world", "hello") // success
assert.NotHasSuffixStringNow(t, "Hello world", "World") // success
assert.NotHasSuffixStringNow(t, "Hello world", "world") // fail and stop the execution
// never runs

func NotIsError added in v1.1.0

func NotIsError(t *testing.T, err, unexpected error, message ...any) error

NotIsError tests whether the error matches the target or not. It'll set the result to fail if the error matches to the target error, and it doesn't stop the execution.

err1 := errors.New("error 1")
err2 := errors.New("error 2")
err3 := errors.New("error 3")
assert.NotIsError(t, err1, err2) // success
assert.NotIsError(t, err1, err1) // fail
assert.NotIsError(t, errors.Join(err1, err2), err3) // success
assert.NotIsError(t, errors.Join(err1, err2), err1) // fail
assert.NotIsError(t, errors.Join(err1, err2), err2) // fail

func NotIsErrorNow added in v1.1.0

func NotIsErrorNow(t *testing.T, err, unexpected error, message ...any) error

NotIsErrorNow tests whether the error matches the target or not. It'll set the result to fail and stop the execution if the error matches to the target error.

err1 := errors.New("error 1")
err2 := errors.New("error 2")
err3 := errors.new("error 3")
assert.NotIsErrorNow(t, errors.Join(err1, err2), err3) // success
assert.NotIsErrorNow(t, err1, err2) // fail
assert.NotIsErrorNow(t, err1, err1) // fail and terminate
// never runs

func NotMapHasKey added in v0.2.1

func NotMapHasKey(t *testing.T, m, key any, message ...any) error

NotMapHasKey tests whether the map contains the specified key or not, it will fail if the map contain the key. It will also set the test result to success if the type of the key cannot assign to the type of the key of the map.

assert.NotMapHasKey(t, map[string]int{"a":1}, "b") // success
assert.NotMapHasKey(t, map[string]int{"a":1}, 1) // success
assert.NotMapHasKey(t, map[string]int{"a":1}, "a") // fail

func NotMapHasKeyNow added in v0.2.1

func NotMapHasKeyNow(t *testing.T, m, key any, message ...any) error

NotMapHasKeyNow tests whether the map contains the specified key or not, it will fail if the map contain the key, and it will terminate the execution if the test fails. It will also set the test result to success if the type of the key cannot assign to the type of the key of the map.

assert.NotMapHasKeyNow(t, map[string]int{"a":1}, "b") // success
assert.NotMapHasKeyNow(t, map[string]int{"a":1}, 1) // success
assert.NotMapHasKeyNow(t, map[string]int{"a":1}, "a") // fail and terminate
// never run

func NotMapHasValue added in v0.2.1

func NotMapHasValue(t *testing.T, m, value any, message ...any) error

NotMapHasValue tests whether the map contains the specified value or not, it will fail if the map contain the value. It will also set the test result to success if the type of the value cannot assign to the type of the value of the map.

assert.NotMapHasValue(t, map[string]int{"a":1}, 2) // success
assert.NotMapHasValue(t, map[string]int{"a":1}, "a") // success
assert.NotMapHasValue(t, map[string]int{"a":1}, 1) // fail

func NotMapHasValueNow added in v0.2.1

func NotMapHasValueNow(t *testing.T, m, value any, message ...any) error

NotMapHasValueNow tests whether the map contains the specified value or not, it will fail if the map contain the value, and it will terminate the execution if the test fails. It will also set the test result to success if the type of the value cannot assign to the type of the value of the map.

assert.NotMapHasValueNow(t, map[string]int{"a":1}, 2) // success
assert.NotMapHasValueNow(t, map[string]int{"a":1}, "a") // success
assert.NotMapHasValueNow(t, map[string]int{"a":1}, 1) // fail and terminate
// never run

func NotMatch added in v0.1.5

func NotMatch(t *testing.T, val string, pattern *regexp.Regexp, message ...any) error

NotMatch tests whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern.

pattern := regexp.MustCompile(`^https?:\/\/`)
assert.NotMatch(t, "example.com", pattern) // success
assert.NotMatch(t, "http://example.com", pattern) // fail

func NotMatchNow added in v0.1.5

func NotMatchNow(t *testing.T, val string, pattern *regexp.Regexp, message ...any) error

NotMatchNow tests whether the string matches the regular expression or not, and it will terminate the execution if the string matches the pattern.

pattern := regexp.MustCompile(`^https?:\/\/`)
assert.NotMatchNow(t, "example.com", pattern) // success
assert.NotMatchNow(t, "http://example.com", pattern) // fail and terminate
// never run

func NotMatchString added in v0.1.5

func NotMatchString(t *testing.T, val, pattern string, message ...any) error

MatchString will compile the pattern and test whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern. It will also panic if the pattern is not a valid regular expression.

assert.NotMatchString(t, "example.com", `^https?:\/\/`) // success
assert.NotMatchString(t, "http://example.com", `^https?:\/\/`) // fail

func NotMatchStringNow added in v0.1.5

func NotMatchStringNow(t *testing.T, val, pattern string, message ...any) error

NotMatchStringNow will compile the pattern and test whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern. It will terminate the execution if the string matches the pattern, and it will panic if the pattern is not a valid regular expression.

assert.NotMatchStringNow(t, "example.com", `^https?:\/\/`) // success
assert.NotMatchStringNow(t, "http://example.com", `^https?:\/\/`) // fail and terminate
// never run

func NotNil added in v0.1.1

func NotNil(t *testing.T, val any, message ...any) error

NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.

var err error // nil
assert.NotNil(t, err) // fail

err = errors.New("some error")
assert.NotNil(t, err) // success

func NotNilNow added in v0.1.2

func NotNilNow(t *testing.T, val any, message ...any) error

NotNilNow tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.

This function will set the result to fail, and stop the execution if the value is nil.

var err error = errors.New("some error")
assert.NotNilNow(t, err) // success

err = nil
assert.NotNilNow(t, err) // fail and terminate
// never run

func NotPanic

func NotPanic(t *testing.T, fn func(), message ...any) error

NotPanic asserts that the function fn does not panic, and it'll set the result to fail if the function panic.

assert.NotPanic(t, func() {
  // no panic
}) // success

assert.NotPanic(t, func() {
  panic("some error")
}) // fail

func NotPanicNow added in v0.1.2

func NotPanicNow(t *testing.T, fn func(), message ...any) error

NotPanicNow asserts that the function fn does not panic. It'll set the result to fail if the function panic, and it also stops the execution.

assert.NotPanicNow(t, func() {
  // no panic
}) // success

assert.NotPanicNow(t, func() {
  panic("some error")
}) // fail and terminate
// never run

func NotPanicOf added in v1.0.2

func NotPanicOf(t *testing.T, fn func(), unexpectedErr any, message ...any) error

NotPanicOf expects the function fn not panic, or the function does not panic by the unexpected error. If the function panics by the unexpected error, it will set the result to fail.

assert.NotPanicOf(t, func() {
  panic("other error")
}, "unexpected error") // success
assert.NotPanicOf(t, func() {
  // ..., no panic
}, "unexpected error") // success
assert.NotPanicOf(t, func() {
  panic("unexpected error")
}, "unexpected error") // fail

func NotPanicOfNow added in v1.0.2

func NotPanicOfNow(t *testing.T, fn func(), unexpectedErr any, message ...any) error

NotPanicOfNow expects the function fn not panic, or the function does not panic by the unexpected error. If the function panics by the unexpected error, it will set the result to fail and stop the execution.

assert.NotPanicOfNow(t, func() {
  panic("other error")
}, "unexpected error") // success
assert.NotPanicOfNow(t, func() {
  // ..., no panic
}, "unexpected error") // success
assert.NotPanicOfNow(t, func() {
  panic("unexpected error")
}, "unexpected error") // fail and terminate
// never runs

func NotTrue added in v0.1.4

func NotTrue(t *testing.T, val any, message ...any) error

NotTrue tests whether a value is truthy or not. It'll set the result to fail if the value is a truthy value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.

assert.NotTrue(t, 0) // success
assert.NotTrue(t, "") // success
assert.NotTrue(t, 1) // fail
assert.NotTrue(t, "test") // fail

func NotTrueNow added in v0.1.4

func NotTrueNow(t *testing.T, val any, message ...any) error

NotTrueNow tests whether a value is truthy or not. It'll set the result to fail if the value is a truthy value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.

The function will stop the execution if the value is truthy.

assert.NotTrueNow(t, 0) // success
assert.NotTrueNow(t, "") // success
assert.NotTrueNow(t, "test") // fail and terminate
// never run

func Panic

func Panic(t *testing.T, fn func(), message ...any) error

Panic expects the function fn to panic, and it'll set the result to fail if the function doesn't panic.

assert.Panic(t, func() {
  panic("some error")
}) // success

assert.Panic(t, func() {
  // no panic
}) // fail

func PanicNow added in v0.1.2

func PanicNow(t *testing.T, fn func(), message ...any) error

PanicNow expects the function fn to panic. It'll set the result to fail if the function doesn't panic, and stop the execution.

assert.PanicNow(t, func() {
  panic("some error")
}) // success

assert.PanicNow(t, func() {
  // no panic
}) // fail
// never run

func PanicOf added in v1.0.2

func PanicOf(t *testing.T, fn func(), expectErr any, message ...any) error

PanicOf expects the function fn to panic by the expected error. If the function does not panic or panic for another reason, it will set the result to fail.

assert.PanicOf(t, func() {
  panic("expected error")
}, "expected error") // success
assert.PanicOf(t, func() {
  panic("unexpected error")
}, "expected error") // fail
assert.PanicOf(t, func() {
  // ..., no panic
}, "expected error") // fail

func PanicOfNow added in v1.0.2

func PanicOfNow(t *testing.T, fn func(), expectErr any, message ...any) error

PanicOfNow expects the function fn to panic by the expected error. If the function does not panic or panic for another reason, it will set the result to fail and terminate the execution.

assert.PanicOfNow(t, func() {
  panic("expected error")
}, "expected error") // success
assert.PanicOfNow(t, func() {
  panic("unexpected error")
}, "expected error") // fail and terminated
// never runs

func True added in v0.1.4

func True(t *testing.T, val any, message ...any) error

True tests whether a value is truthy or not. It'll set the result to fail if the value is a false value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.

assert.True(t, 1) // success
assert.True(t, "test") // success
assert.True(t, 0) // fail
assert.True(t, "") // fail

func TrueNow added in v0.1.4

func TrueNow(t *testing.T, val any, message ...any) error

TrueNow tests whether a value is truthy or not. It'll set the result to fail if the value is a false value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.

The function will stop the execution if the value is falsy.

assert.TrueNow(t, 1) // success
assert.TrueNow(t, "test") // success
assert.TrueNow(t, "") // fail and terminate
// never run

Types

type Assertion

type Assertion struct {
	*testing.T
}

Assertion is the extension of the Go builtin `testing.T`.

Please do not create an Assertion instance without the New function, every assertion function will panic if no inner testing.T set.

func New

func New(t *testing.T) *Assertion

New returns an assertion instance for verifying invariants.

assertion := assert.New(t)
assertion.Equal(actual, expect)
// ...

func (*Assertion) ContainsElement added in v0.2.0

func (a *Assertion) ContainsElement(source, expect any, message ...any) error

NotContainsElement tests whether the array or slice contains the specified element or not, and it set the result to fail if the array or slice does not contain the specified element. It'll panic if the `source` is not an array or a slice.

a := assert.New(t)
a.ContainsElement([]int{1, 2, 3}, 1) // success
a.ContainsElement([]int{1, 2, 3}, 3) // success
a.ContainsElement([]int{1, 2, 3}, 4) // fail

func (*Assertion) ContainsElementNow added in v0.2.0

func (a *Assertion) ContainsElementNow(source, expect any, message ...any) error

ContainsElementNow tests whether the array or slice contains the specified element or not, and it will terminate the execution if the array or slice does not contain the specified element. It'll panic if the `source` is not an array or a slice.

a := assert.New(t)
a.ContainsElementNow([]int{1, 2, 3}, 1) // success
a.ContainsElementNow([]int{1, 2, 3}, 3) // success
a.ContainsElementNow([]int{1, 2, 3}, 4) // fail and stop the execution
// never runs

func (*Assertion) ContainsString added in v0.1.7

func (a *Assertion) ContainsString(str, substr string, message ...any) error

ContainsString tests whether the string contains the substring or not, and it set the result to fail if the string does not contains the substring.

a := assert.New(t)
a.ContainsString("Hello world", "") // success
a.ContainsString("Hello world", "Hello") // success
a.ContainsString("Hello world", "world") // success
a.ContainsString("Hello world", "hello") // fail

func (*Assertion) ContainsStringNow added in v0.1.7

func (a *Assertion) ContainsStringNow(str, substr string, message ...any) error

ContainsStringNow tests whether the string contains the substring or not, and it will terminate the execution if the string does not contains the substring.

a := assert.New(t)
a.ContainsStringNow("Hello world", "") // success
a.ContainsStringNow("Hello world", "Hello") // success
a.ContainsStringNow("Hello world", "world") // success
a.ContainsStringNow("Hello world", "hello") // fail and stop the execution
// never runs

func (*Assertion) DeepEqual

func (a *Assertion) DeepEqual(actual, expect any, message ...any) error

DeepEqual tests the deep equality between actual and expect parameters. It'll set the result to fail if they are not deeply equal, and it doesn't stop the execution.

a := assert.New(t)
a.DeepEqual(1, 1) // success
a.DeepEqual("ABC", "ABC") // success
a.DeepEqual(1, 0) // fail
a.DeepEqual(1, int64(1)) // fail

func (*Assertion) DeepEqualNow added in v0.1.2

func (a *Assertion) DeepEqualNow(actual, expect any, message ...any) error

DeepEqualNow tests the deep equality between actual and expect parameters, and it'll stop the execution if they are not deeply equal.

a := assert.New(t)
a.DeepEqualNow(1, 1) // success
a.DeepEqualNow("ABC", "ABC") // success
a.DeepEqualNow(1, int64(1)) // fail and terminate
// never run

func (*Assertion) Equal added in v0.1.5

func (a *Assertion) Equal(actual, expect any, message ...any) error

Equal tests the equality between actual and expect parameters. It'll set the result to fail if they are not equal, and it doesn't stop the execution.

a := assert.New(t)
a.Equal(1, 1) // success
a.Equal("ABC", "ABC") // success
a.Equal(1, int64(1)) // success
a.Equal(1, uint64(1)) // fail
a.Equal(1, 0) // fail

func (*Assertion) EqualNow added in v0.1.5

func (a *Assertion) EqualNow(actual, expect any, message ...any) error

EqualNow tests the equality between actual and expect parameters, and it'll stop the execution if they are not equal.

a := assert.New(t)
a.EqualNow(1, 1) // success
a.EqualNow("ABC", "ABC") // success
a.EqualNow(1, int64(1)) // success
a.EqualNow(1, 0) // fail and terminate
never run

func (*Assertion) FloatEqual added in v1.1.1

func (a *Assertion) FloatEqual(actual, expect, epsilon any, message ...any) error

FloatEqual tests the equality between actual and expect floating numbers with epsilon. It'll set the result to fail if they are not equal, and it doesn't stop the execution.

a := assert.New(t)
a.FloatEqual(1.0, 1.0, 0.1) // success
a.FloatEqual(1.0, 1.01, 0.1) // success
a.FloatEqual(1.0, 1.2, 0.1) // fail

func (*Assertion) FloatEqualNow added in v1.1.1

func (a *Assertion) FloatEqualNow(actual, expect, epsilon any, message ...any) error

FloatEqualNow tests the equality between actual and expect floating numbers with epsilon, and it'll stop the execution if they are not equal.

a := assert.New(t)
a.FloatEqualNow(1.0, 1.0, 0.1) // success
a.FloatEqualNow(1.0, 1.01, 0.1) // success
a.FloatEqualNow(1.0, 1.2, 0.1) // fail and terminate

func (*Assertion) FloatNotEqual added in v1.1.1

func (a *Assertion) FloatNotEqual(actual, expect, epsilon any, message ...any) error

FloatNotEqual tests the inequality between actual and expect floating numbers with epsilon. It'll set the result to fail if they are equal, but it doesn't stop the execution.

a := assert.New(t)
a.FloatNotEqual(1.0, 1.2, 0.1) // success
a.FloatNotEqual(1.0, 1.1, 0.1) // success
a.FloatNotEqual(1.0, 1.0, 0.1) // fail

func (*Assertion) FloatNotEqualNow added in v1.1.1

func (a *Assertion) FloatNotEqualNow(actual, expect, epsilon any, message ...any) error

FloatNotEqualNow tests the inequality between actual and expect floating numbers with epsilon, and it'll stop the execution if they are equal.

a := assert.New(t)
a.FloatNotEqualNow(1.0, 1.2, 0.1) // success
a.FloatNotEqualNow(1.0, 1.1, 0.1) // success
a.FloatNotEqualNow(1.0, 1.0, 0.1) // fail and terminate

func (*Assertion) Gt added in v1.0.0

func (a *Assertion) Gt(v1, v2 any, message ...string) error

Gt compares the values and sets the result to false if the first value is not greater than to the second value.

a := assert.New(t)
a.Gt(2, 1) // success
a.Gt(3.14, 1.68) // success
a.Gt("BCD", "ABC") // success
a.Gt(2, 2) // fail
a.Gt(1, 2) // fail

func (*Assertion) GtNow added in v1.0.0

func (a *Assertion) GtNow(v1, v2 any, message ...string) error

GtNow compares the values and sets the result to false if the first value is not greater than to the second value. It will panic if they do not match the expected result.

a := assert.New(t)
a.GtNow(2, 1) // success
a.GtNow(3.14, 1.68) // success
a.GtNow("BCD", "ABC") // success
a.GtNow(1, 2) // fail and terminate
// never runs

func (*Assertion) Gte added in v1.0.0

func (a *Assertion) Gte(v1, v2 any, message ...string) error

Gte compares the values and sets the result to false if the first value is not greater than or equal to the second value.

a := assert.New(t)
a.Gte(2, 1) // success
a.Gte(3.14, 1.68) // success
a.Gte("BCD", "ABC") // success
a.Gte(2, 2) // success
a.Gte(1, 2) // fail

func (*Assertion) GteNow added in v1.0.0

func (a *Assertion) GteNow(v1, v2 any, message ...string) error

GteNow compares the values and sets the result to false if the first value is not greater than or equal to the second value. It will panic if they do not match the expected result.

a := assert.New(t)
a.GteNow(2, 1) // success
a.GteNow(3.14, 1.68) // success
a.GteNow("BCD", "ABC") // success
a.GteNow(2, 2) // success
a.GteNow(1, 2) // fail and terminate
// never runs

func (*Assertion) HasPrefixString added in v0.1.7

func (a *Assertion) HasPrefixString(str, prefix string, message ...any) error

HasPrefixString tests whether the string has the prefix string or not, and it set the result to fail if the string does not have the prefix string.

a := assert.New(t)
a.HasPrefixString("Hello world", "") // success
a.HasPrefixString("Hello world", "Hello") // success
a.HasPrefixString("Hello world", "world") // fail
a.HasPrefixString("Hello world", "hello") // fail

func (*Assertion) HasPrefixStringNow added in v0.1.7

func (a *Assertion) HasPrefixStringNow(str, prefix string, message ...any) error

HasPrefixStringNow tests whether the string has the prefix string or not, and it will terminate the execution if the string does not have the prefix string.

a := assert.New(t)
a.HasPrefixStringNow("Hello world", "") // success
a.HasPrefixStringNow("Hello world", "Hello") // success
a.HasPrefixStringNow("Hello world", "hello") // fail and stop the execution
// never runs

func (*Assertion) HasSuffixString added in v0.1.7

func (a *Assertion) HasSuffixString(str, suffix string, message ...any) error

HasSuffixString tests whether the string has the suffix string or not, and it set the result to fail if the string does not have the suffix string.

a := assert.New(t)
a.HasSuffixString("Hello world", "") // success
a.HasSuffixString("Hello world", "world") // success
a.HasSuffixString("Hello world", "World") // fail
a.HasSuffixString("Hello world", "hello") // fail

func (*Assertion) HasSuffixStringNow added in v0.1.7

func (a *Assertion) HasSuffixStringNow(str, suffix string, message ...any) error

HasSuffixStringNow tests whether the string has the suffix string or not, and it will terminate the execution if the string does not have the suffix string.

a := assert.New(t)
a.HasSuffixStringNow("Hello world", "") // success
a.HasSuffixStringNow("Hello world", "world") // success
a.HasSuffixStringNow("Hello world", "World") // fail and stop the execution
// never runs

func (*Assertion) IsError added in v1.1.0

func (a *Assertion) IsError(err, expected error, message ...any) error

IsError tests whether the error matches the target or not. It'll set the result to fail if the error does not match to the target error, and it doesn't stop the execution.

err1 := errors.New("error 1")
err2 := errors.New("error 2")
a := assert.New(t)
a.IsError(err1, err1) // success
a.IsError(err1, err2) // fail
a.IsError(errors.Join(err1, err2), err1) // success
a.IsError(errors.Join(err1, err2), err2) // success

func (*Assertion) IsErrorNow added in v1.1.0

func (a *Assertion) IsErrorNow(err, expected error, message ...any) error

IsErrorNow tests whether the error matches the target or not. It'll set the result to fail and stop the execution if the error does not match to the target error.

err1 := errors.New("error 1")
err2 := errors.New("error 2")
a := assert.New(t)
a.IsErrorNow(errors.Join(err1, err2), err1) // success
a.IsErrorNow(errors.Join(err1, err2), err2) // success
a.IsErrorNow(err1, err1) // success
a.IsErrorNow(err1, err2) // fail
// never runs

func (*Assertion) Lt added in v1.0.0

func (a *Assertion) Lt(v1, v2 any, message ...string) error

Lt compares the values and sets the result to false if the first value is not less than the second value.

a := assert.New(t)
a.Lt(1, 2) // success
a.Lt(1.68, 3.14) // success
a.Lt("ABC", "BCD") // success
a.Lt(2, 2) // fail
a.Lt(2, 1) // fail

func (*Assertion) LtNow added in v1.0.0

func (a *Assertion) LtNow(v1, v2 any, message ...string) error

LtNow compares the values and sets the result to false if the first value is not less than the second value. It will panic if they do not match the expected result.

a := assert.New(t)
a.LtNow(1, 2) // success
a.LtNow(1.68, 3.14) // success
a.LtNow("ABC", "BCD") // success
a.LtNow(2, 1) // fail and terminate
// never runs

func (*Assertion) Lte added in v1.0.0

func (a *Assertion) Lte(v1, v2 any, message ...string) error

Lte compares the values and sets the result to false if the first value is not less than or equal to the second value.

a := assert.New(t)
a.Lte(1, 2) // success
a.Lte(1.68, 3.14) // success
a.Lte("ABC", "BCD") // success
a.Lte(2, 2) // success
a.Lte(2, 1) // fail

func (*Assertion) LteNow added in v1.0.0

func (a *Assertion) LteNow(v1, v2 any, message ...string) error

LteNow compares the values and sets the result to false if the first value is not less than or equal to the second value. It will panic if they do not match the expected result.

a := assert.New(t)
a.LteNow(1, 2) // success
a.LteNow(1.68, 3.14) // success
a.LteNow("ABC", "BCD") // success
a.LteNow(2, 2) // success
a.LteNow(2, 1) // fail and terminate
// never runs

func (*Assertion) MapHasKey added in v0.2.1

func (a *Assertion) MapHasKey(m, key any, message ...any) error

MapHasKey tests whether the map contains the specified key or not, it will fail if the map does not contain the key, or the type of the key cannot assign to the type of the key of the map.

a := assert.New(t)
a.MapHasKey(map[string]int{"a":1}, "a") // success
a.MapHasKey(map[string]int{"a":1}, "b") // fail
a.MapHasKey(map[string]int{"a":1}, 1) // fail

func (*Assertion) MapHasKeyNow added in v0.2.1

func (a *Assertion) MapHasKeyNow(m, key any, message ...any) error

MapHasKeyNow tests whether the map contains the specified key or not, and it will terminate the execution if the test fails. It will fail if the map does not contain the key, or the type of the key cannot assign to the type of the key of the map.

a := assert.New(t)
a.MapHasKeyNow(map[string]int{"a":1}, "a") // success
a.MapHasKeyNow(map[string]int{"a":1}, "b") // fail and terminate
// never run

func (*Assertion) MapHasValue added in v0.2.1

func (a *Assertion) MapHasValue(m, value any, message ...any) error

MapHasValue tests whether the map contains the specified value or not, it will fail if the map does not contain the value, or the type of the value cannot assign to the type of the values of the map.

a := assert.New(t)
a.MapHasValue(map[string]int{"a":1}, 1) // success
a.MapHasValue(map[string]int{"a":1}, 2) // fail
a.MapHasValue(map[string]int{"a":1}, "a") // fail

func (*Assertion) MapHasValueNow added in v0.2.1

func (a *Assertion) MapHasValueNow(m, value any, message ...any) error

MapHasValueNow tests whether the map contains the specified value or not, and it will terminate the execution if the test fails. It will fail if the map does not contain the value, or the type of the value cannot assign to the type of the value of the map.

a := assert.New(t)
a.MapHasValueNow(map[string]int{"a":1}, 1) // success
a.MapHasValueNow(map[string]int{"a":1}, 2) // fail and terminate
// never run

func (*Assertion) Match added in v0.1.5

func (a *Assertion) Match(val string, pattern *regexp.Regexp, message ...any) error

Match tests whether the string matches the regular expression or not.

a := assert.New(t)
pattern := regexp.MustCompile(`^https?:\/\/`)
a.Match("http://example.com", pattern) // success
a.Match("example.com", pattern) // fail

func (*Assertion) MatchNow added in v0.1.5

func (a *Assertion) MatchNow(val string, pattern *regexp.Regexp, message ...any) error

MatchNow tests whether the string matches the regular expression or not, and it will terminate the execution if it does not match.

a := assert.New(t)
pattern := regexp.MustCompile(`^https?:\/\/`)
a.MatchNow("http://example.com", pattern) // success
a.MatchNow("example.com", pattern) // fail and terminate
// never run

func (*Assertion) MatchString added in v0.1.5

func (a *Assertion) MatchString(val, pattern string, message ...any) error

MatchString will compile the pattern and test whether the string matches the regular expression or not. It will panic if the pattern is not a valid regular expression.

a := assert.New(t)
a.MatchString("http://example.com", `^https?:\/\/`) // success
a.MatchString("example.com", `^https?:\/\/`) // fail

func (*Assertion) MatchStringNow added in v0.1.5

func (a *Assertion) MatchStringNow(val, pattern string, message ...any) error

MatchStringNow will compile the pattern and test whether the string matches the regular expression or not. It will terminate the execution if it does not match, and it will panic if the pattern is not a valid regular expression.

a := assert.New(t)
a.MatchStringNow("http://example.com", `^https?:\/\/`) // success
a.MatchStringNow("example.com", `^https?:\/\/`) // fail and terminate
// never run

func (*Assertion) Nil added in v0.1.1

func (a *Assertion) Nil(val any, message ...any) error

Nil tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.

a := assert.New(t)
var err error // nil
a.Nil(err) // success

err = errors.New("some error")
a.Nil(err) // fail

func (*Assertion) NilNow added in v0.1.2

func (a *Assertion) NilNow(val any, message ...any) error

NilNow tests whether a value is nil or not, and it'll fail when the value is not nil. It will always return false if the value is a bool, an integer, a floating number, a complex, or a string.

This function will set the result to fail, and stop the execution if the value is not nil.

a := assert.New(t)
var err error // nil
a.NilNow(err) // success

err = errors.New("some error")
a.NilNow(err) // fail and terminate
// never run

func (*Assertion) NotContainsElement added in v0.2.0

func (a *Assertion) NotContainsElement(source, expect any, message ...any) error

NotContainsElement tests whether the array or slice contains the specified element or not, and it set the result to fail if the array or slice contains the specified element. It'll panic if the `source` is not an array or a slice.

a := assert.New(t)
a.NotContainsElement([]int{1, 2, 3}, 4) // success
a.NotContainsElement([]int{1, 2, 3}, 0) // success
a.NotContainsElement([]int{1, 2, 3}, 1) // fail

func (*Assertion) NotContainsElementNow added in v0.2.0

func (a *Assertion) NotContainsElementNow(source, expect any, message ...any) error

NotContainsElementNow tests whether the array or slice contains the specified element or not, and it will terminate the execution if the array or slice contains the specified element. It'll panic if the `source` is not an array or a slice.

a := assert.New(t)
a.NotContainsElementNow([]int{1, 2, 3}, 4) // success
a.NotContainsElementNow([]int{1, 2, 3}, 0) // success
a.NotContainsElementNow([]int{1, 2, 3}, 1) // fail and stop the execution
// never runs

func (*Assertion) NotContainsString added in v0.1.7

func (a *Assertion) NotContainsString(str, substr string, message ...any) error

NotContainsString tests whether the string contains the substring or not, and it set the result to fail if the string contains the substring.

a := assert.New(t)
a.NotContainsString("Hello world", "hello") // success
a.NotContainsString("Hello world", "") // fail
a.NotContainsString("Hello world", "Hello") // fail
a.NotContainsString("Hello world", "world") // fail

func (*Assertion) NotContainsStringNow added in v0.1.7

func (a *Assertion) NotContainsStringNow(str, substr string, message ...any) error

NotContainsStringNow tests whether the string contains the substring or not, and it will terminate the execution if the string contains the substring.

a := assert.New(t)
a.NotContainsStringNow("Hello world", "hello") // success
a.NotContainsStringNow("Hello world", "Hello") // fail and stop the execution
// never runs

func (*Assertion) NotDeepEqual

func (a *Assertion) NotDeepEqual(actual, expect any, message ...any) error

NotDeepEqual tests the deep inequality between actual and expected parameters. It'll set the result to fail if they are deeply equal, but it doesn't stop the execution.

a := assert.New(t)
a.NotDeepEqual(1, 0) // success
a.NotDeepEqual(1, int64(1)) // success
a.NotDeepEqual(1, 1) // fail
a.NotDeepEqual("ABC", "ABC") // fail

func (*Assertion) NotDeepEqualNow added in v0.1.2

func (a *Assertion) NotDeepEqualNow(actual, expect any, message ...any) error

NotDeepEqualNow tests the deep inequality between actual and expected parameters, and it'll stop the execution if they are deeply equal.

a := assert.New(t)
a.NotDeepEqual1, 0) // success
a.NotDeepEqual1, int64(1)) // success
a.NotDeepEqual"ABC", "ABC") // fail and terminate
// never run

func (*Assertion) NotEqual added in v0.1.5

func (a *Assertion) NotEqual(actual, expect any, message ...any) error

NotEqual tests the inequality between actual and expected parameters. It'll set the result to fail if they are equal, but it doesn't stop the execution.

a := assert.New(t)
a.NotEqual(1, 0) // success
a.NotEqual("ABC", "CBA") // success
a.NotEqual(1, uint64(1)) // success
a.NotEqual(1, 1) // fail
a.NotEqual("ABC", "ABC") // fail
a.NotEqual(1, int64(1)) // fail

func (*Assertion) NotEqualNow added in v0.1.5

func (a *Assertion) NotEqualNow(actual, expect any, message ...any) error

NotEqualNow tests the inequality between actual and expected parameters, and it'll stop the execution if they are equal.

a := assert.New(t)
a.NotEqualNow(1, 0) // success
a.NotEqualNow("ABC", "CBA") // success
a.NotEqualNow(1, 1) // fail and terminate
// never run

func (*Assertion) NotHasPrefixString added in v0.1.7

func (a *Assertion) NotHasPrefixString(str, prefix string, message ...any) error

NotHasPrefixString tests whether the string has the prefix string or not, and it set the result to fail if the string have the prefix string.

a := assert.New(t)
a.NotHasPrefixString("Hello world", "hello") // success
a.NotHasPrefixString("Hello world", "world") // success
a.NotHasPrefixString("Hello world", "") // fail
a.NotHasPrefixString("Hello world", "Hello") // fail

func (*Assertion) NotHasPrefixStringNow added in v0.1.7

func (a *Assertion) NotHasPrefixStringNow(str, prefix string, message ...any) error

NotHasPrefixStringNow tests whether the string has the prefix string or not, and it will terminate the execution if the string have the prefix string.

a := assert.New(t)
a.NotHasPrefixStringNow("Hello world", "hello") // success
a.NotHasPrefixStringNow("Hello world", "world") // success
a.NotHasPrefixStringNow("Hello world", "Hello") // fail and stop the execution
// never runs

func (*Assertion) NotHasSuffixString added in v0.1.7

func (a *Assertion) NotHasSuffixString(str, suffix string, message ...any) error

NotHasSuffixString tests whether the string has the suffix string or not, and it set the result to fail if the string have the suffix string.

a := assert.New(t)
a.NotHasSuffixString("Hello world", "Hello") // success
a.NotHasSuffixString("Hello world", "World") // success
a.NotHasSuffixString("Hello world", "") // fail
a.NotHasSuffixString("Hello world", "world") // fail

func (*Assertion) NotHasSuffixStringNow added in v0.1.7

func (a *Assertion) NotHasSuffixStringNow(str, suffix string, message ...any) error

NotHasSuffixStringNow tests whether the string has the suffix string or not, and it will terminate the execution if the string have the suffix string.

a := assert.New(t)
a.NotHasSuffixStringNow("Hello world", "hello") // success
a.NotHasSuffixStringNow("Hello world", "World") // success
a.NotHasSuffixStringNow("Hello world", "world") // fail and stop the execution
// never runs

func (*Assertion) NotIsError added in v1.1.0

func (a *Assertion) NotIsError(err, unexpected error, message ...any) error

NotIsError tests whether the error matches the target or not. It'll set the result to fail if the error matches to the target error, and it doesn't stop the execution.

a := assert.New(t)
err1 := errors.New("error 1")
err2 := errors.New("error 2")
err3 := errors.New("error 3")
a.NotIsError(err1, err2) // success
a.NotIsError(err1, err1) // fail
a.NotIsError(errors.Join(err1, err2), err3) // success
a.NotIsError(errors.Join(err1, err2), err1) // fail
a.NotIsError(errors.Join(err1, err2), err2) // fail

func (*Assertion) NotIsErrorNow added in v1.1.0

func (a *Assertion) NotIsErrorNow(err, unexpected error, message ...any) error

NotIsErrorNow tests whether the error matches the target or not. It'll set the result to fail and stop the execution if the error matches to the target error.

a := assert.New(t)
err1 := errors.New("error 1")
err2 := errors.New("error 2")
err3 := errors.new("error 3")
a.NotIsErrorNow(errors.Join(err1, err2), err3) // success
a.NotIsErrorNow(err1, err2) // fail
a.NotIsErrorNow(err1, err1) // fail and terminate
// never runs

func (*Assertion) NotMapHasKey added in v0.2.1

func (a *Assertion) NotMapHasKey(m, key any, message ...any) error

NotMapHasKey tests whether the map contains the specified key or not, it will fail if the map contain the key. It will also set the test result to success if the type of the key cannot assign to the type of the key of the map.

a := assert.New(t)
a.NotMapHasKey(map[string]int{"a":1}, "b") // success
a.NotMapHasKey(map[string]int{"a":1}, 1) // success
a.NotMapHasKey(map[string]int{"a":1}, "a") // fail

func (*Assertion) NotMapHasKeyNow added in v0.2.1

func (a *Assertion) NotMapHasKeyNow(m, key any, message ...any) error

NotMapHasKeyNow tests whether the map contains the specified key or not, it will fail if the map contain the key, and it will terminate the execution if the test fails. It will also set the test result to success if the type of the key cannot assign to the type of the key of the map.

a := assert.New(t)
a.NotMapHasKeyNow(map[string]int{"a":1}, "b") // success
a.NotMapHasKeyNow(map[string]int{"a":1}, 1) // success
a.NotMapHasKeyNow(map[string]int{"a":1}, "a") // fail and terminate
// never run

func (*Assertion) NotMapHasValue added in v0.2.1

func (a *Assertion) NotMapHasValue(m, value any, message ...any) error

NotMapHasValue tests whether the map contains the specified value or not, it will fail if the map contain the value. It will also set the test result to success if the type of the value cannot assign to the type of the value of the map.

a := assert.New(t)
a.NotMapHasValue(map[string]int{"a":1}, 2) // success
a.NotMapHasValue(map[string]int{"a":1}, "a") // success
a.NotMapHasValue(map[string]int{"a":1}, 1) // fail

func (*Assertion) NotMapHasValueNow added in v0.2.1

func (a *Assertion) NotMapHasValueNow(m, value any, message ...any) error

NotMapHasValueNow tests whether the map contains the specified value or not, it will fail if the map contain the value, and it will terminate the execution if the test fails. It will also set the test result to success if the type of the value cannot assign to the type of the value of the map.

a := assert.New(t)
a.NotMapHasValueNow(map[string]int{"a":1}, 2) // success
a.NotMapHasValueNow(map[string]int{"a":1}, "a") // success
a.NotMapHasValueNow(map[string]int{"a":1}, 1) // fail and terminate
// never run

func (*Assertion) NotMatch added in v0.1.5

func (a *Assertion) NotMatch(val string, pattern *regexp.Regexp, message ...any) error

NotMatch tests whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern.

a := assert.New(t)
pattern := regexp.MustCompile(`^https?:\/\/`)
a.NotMatch("example.com", pattern) // success
a.NotMatch("http://example.com", pattern) // fail

func (*Assertion) NotMatchNow added in v0.1.5

func (a *Assertion) NotMatchNow(val string, pattern *regexp.Regexp, message ...any) error

NotMatchNow tests whether the string matches the regular expression or not, and it will terminate the execution if the string matches the pattern.

a := assert.New(t)
pattern := regexp.MustCompile(`^https?:\/\/`)
a.NotMatchNow("example.com", pattern) // success
a.NotMatchNow("http://example.com", pattern) // fail and terminate
// never run

func (*Assertion) NotMatchString added in v0.1.5

func (a *Assertion) NotMatchString(val, pattern string, message ...any) error

MatchString will compile the pattern and test whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern. It will also panic if the pattern is not a valid regular expression.

a := assert.New(t)
a.NotMatchString("example.com", `^https?:\/\/`) // success
a.NotMatchString("http://example.com", `^https?:\/\/`) // fail

func (*Assertion) NotMatchStringNow added in v0.1.5

func (a *Assertion) NotMatchStringNow(val, pattern string, message ...any) error

NotMatchStringNow will compile the pattern and test whether the string matches the regular expression or not, and it set the result to fail if the string matches the pattern. It will terminate the execution if the string matches the pattern, and it will panic if the pattern is not a valid regular expression.

a := assert.New(t)
a.NotMatchStringNow("example.com", `^https?:\/\/`) // success
a.NotMatchStringNow("http://example.com", `^https?:\/\/`) // fail and terminate
// never run

func (*Assertion) NotNil added in v0.1.1

func (a *Assertion) NotNil(val any, message ...any) error

NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.

a := assert.New(t)
var err error // nil
a.NotNil(err) // fail

err = errors.New("some error")
a.NotNil(err) // success

func (*Assertion) NotNilNow added in v0.1.2

func (a *Assertion) NotNilNow(val any, message ...any) error

NotNilNow tests whether a value is nil or not, and it'll fail when the value is nil. It will always return true if the value is a bool, an integer, a floating number, a complex, or a string.

This function will set the result to fail, and stop the execution if the value is nil.

a := assert.New(t)
var err error = errors.New("some error")
a.NotNilNow(err) // success

err = nil
a.NotNilNow(err) // fail and terminate
// never run

func (*Assertion) NotPanic

func (a *Assertion) NotPanic(fn func(), message ...any) error

NotPanic asserts that the function fn does not panic, and it'll set the result to fail if the function panic.

a := assert.New(t)
a.NotPanic(func() {
  // no panic
}) // success

a.NotPanic(func() {
  panic("some error")
}) // fail

func (*Assertion) NotPanicNow added in v0.1.2

func (a *Assertion) NotPanicNow(fn func(), message ...any) error

NotPanicNow asserts that the function fn does not panic. It'll set the result to fail if the function panic, and it also stops the execution.

a := assert.New(t)
a.NotPanicNow(func() {
  // no panic
}) // success

a.NotPanicNow(func() {
  panic("some error")
}) // fail and terminate
// never run

func (*Assertion) NotPanicOf added in v1.0.2

func (a *Assertion) NotPanicOf(fn func(), unexpectedErr any, message ...any) error

NotPanicOf expects the function fn not panic, or the function does not panic by the unexpected error. If the function panics by the unexpected error, it will set the result to fail.

a := assert.New(t)
a.NotPanicOf(func() {
  panic("other error")
}, "unexpected error") // success
a.NotPanicOf(func() {
  // ..., no panic
}, "unexpected error") // success
a.NotPanicOf(func() {
  panic("unexpected error")
}, "unexpected error") // fail

func (*Assertion) NotPanicOfNow added in v1.0.2

func (a *Assertion) NotPanicOfNow(fn func(), unexpectedErr any, message ...any) error

NotPanicOfNow expects the function fn not panic, or the function does not panic by the unexpected error. If the function panics by the unexpected error, it will set the result to fail and stop the execution.

a := assert.New(t)
a.NotPanicOfNow(func() {
  panic("other error")
}, "unexpected error") // success
a.NotPanicOfNow(func() {
  // ..., no panic
}, "unexpected error") // success
a.NotPanicOfNow(func() {
  panic("unexpected error")
}, "unexpected error") // fail and terminate
// never runs

func (*Assertion) NotTrue added in v0.1.4

func (a *Assertion) NotTrue(val any, message ...any) error

NotTrue tests whether a value is truthy or not. It'll set the result to fail if the value is a truthy value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.

a := assert.New(t)
a.NotTrue(0) // success
a.NotTrue("") // success
a.NotTrue(1) // fail
a.NotTrue("test") // fail

func (*Assertion) NotTrueNow added in v0.1.4

func (a *Assertion) NotTrueNow(val any, message ...any) error

NotTrueNow tests whether a value is truthy or not. It'll set the result to fail if the value is a truthy value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.

The function will stop the execution if the value is truthy.

a := assert.New(t)
a.NotTrueNow(0) // success
a.NotTrueNow("") // success
a.NotTrueNow("test") // fail and terminate
// never run

func (*Assertion) Panic

func (a *Assertion) Panic(fn func(), message ...any) error

Panic expects the function fn to panic, and it'll set the result to fail if the function doesn't panic.

a := assert.New(t)
a.Panic(func() {
  panic("some error")
}) // success

a.Panic(func() {
  // no panic
}) // fail

func (*Assertion) PanicNow added in v0.1.2

func (a *Assertion) PanicNow(fn func(), message ...any) error

PanicNow expects the function fn to panic. It'll set the result to fail if the function doesn't panic, and stop the execution.

a := assert.New(t)
a.PanicNow(func() {
  panic("some error")
}) // success

a.PanicNow(func() {
  // no panic
}) // fail
// never run

func (*Assertion) PanicOf added in v1.0.2

func (a *Assertion) PanicOf(fn func(), expectErr any, message ...any) error

PanicOf expects the function fn to panic by the expected error. If the function does not panic or panic for another reason, it will set the result to fail.

a := assert.New(t)
a.PanicOf(func() {
  panic("expected error")
}, "expected error") // success
a.PanicOf(func() {
  panic("unexpected error")
}, "expected error") // fail
a.PanicOf(func() {
  // ..., no panic
}, "expected error") // fail

func (*Assertion) PanicOfNow added in v1.0.2

func (a *Assertion) PanicOfNow(fn func(), expectErr any, message ...any) error

PanicOfNow expects the function fn to panic by the expected error. If the function does not panic or panic for another reason, it will set the result to fail and terminate the execution.

a := assert.New(t)
a.PanicOfNow(func() {
  panic("expected error")
}, "expected error") // success
a.PanicOfNow(func() {
  panic("unexpected error")
}, "expected error") // fail and terminated
// never runs

func (*Assertion) Run added in v0.1.1

func (assertion *Assertion) Run(name string, f func(a *Assertion)) bool

Run runs f as a subtest of a called name. It runs f in a separate goroutine and blocks until f returns or calls a.Parallel to become a parallel test. Run reports whether f succeeded (or at least did not fail before calling t.Parallel).

Run may be called simultaneously from multiple goroutines, but all such calls must return before the outer test function for a returns.

assertion := assert.New(t)
assertion.Run("SubTest", func (a *assert.Assertion) bool {
  // TODO...
})

func (*Assertion) True added in v0.1.4

func (a *Assertion) True(val any, message ...any) error

True tests whether a value is truthy or not. It'll set the result to fail if the value is a false value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.

a := assert.New(t)
a.True(1) // success
a.True("test") // success
a.True(0) // fail
a.True("") // fail

func (*Assertion) TrueNow added in v0.1.4

func (a *Assertion) TrueNow(val any, message ...any) error

TrueNow tests whether a value is truthy or not. It'll set the result to fail if the value is a false value. For most types of value, a falsy value is the zero value for its type. For a slice, a truthy value should not be nil, and its length must be greater than 0. For nil, the value is always falsy.

The function will stop the execution if the value is falsy.

a := assert.New(t)
a.TrueNow(1) // success
a.TrueNow("test") // success
a.TrueNow("") // fail and terminate
// never run

type AssertionError

type AssertionError struct {
	// contains filtered or unexported fields
}

AssertionError indicates the failure of an assertion.

func (AssertionError) Error

func (err AssertionError) Error() string

Error returns the message of the error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL