assert

package
v0.0.0-...-e463486 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallerInfo

func CallerInfo() []string

CallerInfo returns an array of strings containing the file and line number of each stack frame leading from the current test to the assert call that failed.

func Empty

func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool

Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either a slice or a channel with len == 0.

assert.Empty(t, obj)

func Equal

func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool

Equal asserts that two objects are equal.

assert.Equal(t, 123, 123)

Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.

func Error

func Error(t TestingT, err error, msgAndArgs ...interface{}) bool

Error asserts that a function returned an error (i.e. not `nil`).

  actualObj, err := SomeFunction()
  if assert.Error(t, err) {
	   assert.Equal(t, expectedError, err)
  }

func Fail

func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool

Fail reports a failure through

func False

func False(t TestingT, value bool, msgAndArgs ...interface{}) bool

False asserts that the specified value is false.

assert.False(t, myBool)

func Len

func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) bool

Len asserts that the specified object has specific length. Len also fails if the object has a type that len() not accept.

assert.Len(t, mySlice, 3)

func Nil

func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool

Nil asserts that the specified object is nil.

assert.Nil(t, err)

func NoError

func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool

NoError asserts that a function returned no error (i.e. `nil`).

  actualObj, err := SomeFunction()
  if assert.NoError(t, err) {
	   assert.Equal(t, expectedObj, actualObj)
  }

func NotEmpty

func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool

NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either a slice or a channel with len == 0.

if assert.NotEmpty(t, obj) {
  assert.Equal(t, "two", obj[1])
}

func NotEqual

func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool

NotEqual asserts that the specified values are NOT equal.

assert.NotEqual(t, obj1, obj2)

Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses).

func NotNil

func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool

NotNil asserts that the specified object is not nil.

assert.NotNil(t, err)

func ObjectsAreEqual

func ObjectsAreEqual(expected, actual interface{}) bool

ObjectsAreEqual determines if two objects are considered equal.

This function does no assertion of any kind.

func True

func True(t TestingT, value bool, msgAndArgs ...interface{}) bool

True asserts that the specified value is true.

assert.True(t, myBool)

Types

type TestingT

type TestingT interface {
	Errorf(format string, args ...interface{})
}

TestingT is an interface wrapper around *testing.T

Jump to

Keyboard shortcuts

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