Skip to content
/ assert Public
forked from bmizerany/assert

Simple test assertions for Golang tests

Notifications You must be signed in to change notification settings

stvp/assert

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Assert

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

Documentation

Installation

$ go get github.com/stvp/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 WithinDuration(t *testing.T, duration time.Duration, goalTime, gotTime time.Time, messages ...interface{})
func Panics( t *testing.T, expected interface{}, messages ...interface{} )

Example

package main

import "github.com/stvp/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.

About

Simple test assertions for Golang tests

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%