assert

package module
v0.0.0-...-c06f542 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2016 License: MIT Imports: 3 Imported by: 0

README

go-assert - lightweight assertion

GoDoc

Simple assertion library for unit testing in Golang without vendoring/dependencies.

Design principles:

  • No additional dependencies
  • Readability

Check the documentation about the available features/functions

Installation and update

Installation:

go get github.com/lexandro/go-assert

Update:

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

Usage

// required imports
import (
	"github.com/lexandro/go-assert"
	"testing"
)

// Simple equality test
func Test_Equals(t *testing.T) {
	assert.Equals(t, 1, 1)
}

// Simple non-equality test
func Test_NotEquals(t *testing.T) {
	assert.NotEquals(t, 2, 3)
}

// Simple test for nil
func Test_IsNil(t *testing.T) {
	assert.IsNil(t, nil)
}

// Simple test for not nil
func Test_IsNotNil(t *testing.T) {
	assert.IsNotNil(t, "")
}

// Simple test for true
func Test_IsTrue(t *testing.T) {
	assert.IsTrue(t, true)
}

// Simple test for false
func Test_IsFalse(t *testing.T) {
	assert.IsFalse(t, false)
}

TODO:

assert.IsEmpty

Contributing

We would love for you to contribute to go-assert. Fork the repository and send a PR with the fix or report any issues!

Documentation

Overview

Package assert is lightweight framework of common assertions to make unit testing easier and readable

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equals

func Equals(t *testing.T, exp interface{}, act interface{}) (result bool)

Equals asserts the equality of the given arguments

assert.Equals(t, 111, 111)

Returns true if the arguments are equal and false if different.

func IsFalse

func IsFalse(t *testing.T, v bool) bool

IsFalse asserts the given bool argument is false

assert.IsFalse(t, false)

Returns the negated value of the argument

func IsNil

func IsNil(t *testing.T, v interface{}) bool

IsNil asserts the given argument is nil

assert.IsNil(t, nil)

Returns true if the argument is nil and false if initialized to something.

func IsNotNil

func IsNotNil(t *testing.T, v interface{}) bool

IsNotNil asserts the given argument is initialized

assert.IsNotNil(t, 1)

Returns true if the argument is initialized and false if nil.

func IsTrue

func IsTrue(t *testing.T, v bool) bool

IsTrue asserts the given bool argument is true

assert.IsTrue(t, true)

Returns the argument's value

func NotEquals

func NotEquals(t *testing.T, exp interface{}, act interface{}) (result bool)

NotEquals asserts the non-equality of the given arguments

assert.NotEquals(t, 111, 222)

Returns true if the arguments are not equal and false if equal.

Types

This section is empty.

Jump to

Keyboard shortcuts

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