Skip to content
Simple test assertions for Golang tests
Go
Branch: master
Clone or download
Pull request Compare This branch is 5 commits ahead, 3 commits behind stvp:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
README.md
assert.go
assert_test.go

README.md

Assert

Simple test assertions for Go. This is a fork of a fork of a bmizerany/assert with improved support for things like nil pointers, etc.

Documentation

Installation

$ go get github.com/bruth/assert

API

func Equal(t *testing.T, expected, got interface{}, messages ...interface{})
func NotEqual(t *testing.T, expected, got interface{}, messages ...interface{})
func True(t *testing.T, got interface{}, messages ...interface{})
func False(t *testing.T, got interface{}, messages ...interface{})
func Nil(t *testing.T, got interface{}, messages ...interface{})
func NotNil(t *testing.T, got interface{}, messages ...interface{})
func Contains(t *testing.T, expected string, got string, messages ...interface{})
func NotContains(t *testing.T, unexpected string, got string, messages ...interface{})
func Panic(t *testing.T, err interface{}, fn func(), messages ...interface{})

Example

package main

import "github.com/bruth/assert"

type CoolStruct struct{}

func TestThings(t *testing.T) {
  myString := "cool"

  assert.Equal(t, "cool", myString, "myString should be equal")
  assert.NotEqual(t, "nope", myString)

  var myStruct CoolStruct
  assert.Nil(t, myStruct)
}

See assert_test.go for more usage examples.

Output

You can add extra information to test failures by passing in any number of extra arguments:

assert.Equal(t, "foo", myString, "Should set up a proper foo string")
% go test
--- FAIL: TestImportantFeature (0.00 seconds)
	assert.go:18: /Users/tyson/go/src/github.com/foo/bar/main_test.go:31
	assert.go:38: 💩  Unexpected: "foo"
	assert.go:40: 💩  - Should set up a proper foo string
FAIL
exit status 1
FAIL	github.com/foo/bar	0.017s

License

Copyright Blake Mizerany and Keith Rarick. Licensed under the MIT license. Additional modifications by Stovepipe Studios.

You can’t perform that action at this time.