Help us shape the future of Go! Take the 2026 Go Developer Survey

goassertions

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2019 License: LGPL-3.0 Imports: 1 Imported by: 0

README

goassertions

Assertions for use in go unit testing, currently only implementing an Equal assertion that compares two variables of any type. Lets you bundle several assertions inside single test function without many if-statements

How to use

Instead of the standard way, implement your test function like the following:

import (
  "testing"
  assert "github.com/morngrar/goassertions"
)

func TestYourFunc(t testing.T) {
  assert.Equal(YourFunc(params), expectedValue, "YourFunc should return X")
  ...
  if assert.Failures() { // some assertion failed
    t.Error("YourFunc assertions failed")
  }
}

The test output on failures might look like this:

YourFunc should return X, got Y
[...]
--- FAIL: TestYourFunc (0.00s)
    youstuff_test.go:14: YourFunc assertions failed
FAIL
exit status 1
FAIL	yourstuff	0.003s

Contributing

PRs implementing further assertions or other improvements are welcome; however, tests are a requirement. At least cover your code as well as the existing Equal function.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(got interface{}, want interface{}, msg string)

Equal prints the given message on failure, and sets the pass variable

func Failures added in v0.2.1

func Failures() bool

Failures returns the inverse of the internal pass variable, and resets it

func InEqual added in v0.4.0

func InEqual(got interface{}, different interface{}, msg string)

InEqual prints the given message on failure, and sets the pass variable

Types

This section is empty.

Jump to

Keyboard shortcuts

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