如何在Go测试中使用调试消息进行断言?

huangapple go评论77阅读模式
英文:

How to assert with a debug message in Go tests?

问题

我想这样做:

test.FailNow("My Message")

但是test.T.FailNow不接受消息。我目前正在这样做:

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

有更好的方法吗?

英文:

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?

答案1

得分: 9

参见:http://golang.org/pkg/testing/#T.Fatal(和Fatalf)

文档中说:“Fatal等同于Log()后跟FailNow()。”

英文:

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

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

答案2

得分: 2

我在我的Tideland Common Go Library中构建了一个小的辅助包(参见http://code.google.com/p/tcgl/)。API文档可以在http://go.pkgdoc.org/code.google.com/p/tcgl/asserts找到。

英文:

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.

huangapple
  • 本文由 发表于 2012年6月3日 19:16:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/10869843.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定