Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assert with a debug message in Go tests?

Tags:

go

I want to do this:

test.FailNow("My Message")

but test.T.FailNow doesn't take a message. I am currently doing:

log.Println("Expected exception but got none")
test.FailNow()

Is there a better way?

like image 696
Joe Avatar asked Jun 03 '12 11:06

Joe


2 Answers

See: http://golang.org/pkg/testing/#T.Fatal (and Fatalf)

The docs say: "Fatal is equivalent to Log() followed by FailNow()."

like image 75
zzzz Avatar answered Sep 30 '22 09:09

zzzz


I build a little helping package as part of my Tideland Common Go Library (see http://code.google.com/p/tcgl/). The API doc can found at http://go.pkgdoc.org/code.google.com/p/tcgl/asserts.

like image 23
themue Avatar answered Sep 30 '22 10:09

themue