assert

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2018 License: BSD-3-Clause Imports: 5 Imported by: 0

README

assert

GoDoc CircleCI Go Report Card

assert implements functions for making assertions in tests.

Installation

The recommended way to install assert is with dep.

dep ensure -add github.com/dapr-project/assert@v1.0.0

Where v1.0.0 is the version you want to pin to. Alternatively you can go get the package into your $GOPATH.

go get -u github.com/dapr-project/assert

Once installed you can import into your project.

import "github.com/dapr-project/assert"

Usage

Use the assert.OK() function inside to assert expected results.

func TestMax(t *testing.T) {
  max := math.Max(1.0, 3.0)
  assert.OK(t, max == 3.0, "max isn't 3.0")
}

Use the assert.Includes() function to assert an element is included in a list.

func TestSplit(t *testing.T) {
  words := strings.Split("hello world", " ")
  assert.Includes(t, words, "hello", "words excludes 'hello'")
}

Use the assert.Excludes() function to assert an element is excluded from a list.

func TestSplit(t *testing.T) {
  words := strings.Split("hello world", " ")
  assert.Excludes(t, words, "foobar", "words includes 'foobar'")
}

Use the assert.Unique() function to assert an element is only included once in a list.

func TestSplit(t *testing.T) {
  letters := strings.Split("hello", "")
  assert.Unique(t, letters, "h", "letters includes 'h' multiple times")
}

Documentation

Overview

Package assert implements functions for making assertions in tests.

Index

Constants

This section is empty.

Variables

View Source
var TestSilent bool

TestSilent is used to hide test output when running tests.

Functions

func Excludes added in v1.1.0

func Excludes(t *testing.T, list interface{}, elem interface{}, msg string)

func Includes added in v1.1.0

func Includes(t *testing.T, list interface{}, elem interface{}, msg string)

Includes asserts that elem can be found within list using reflection.

func OK

func OK(t *testing.T, expr bool, msg string)

OK asserts that the given expression is true, else fails the given test.

func Unique added in v1.1.0

func Unique(t *testing.T, list interface{}, elem interface{}, msg string)

Unique ..

Types

This section is empty.

Jump to

Keyboard shortcuts

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