英文:
How do I mark a test as inconclusive in Go?
问题
在Go语言中编写测试时,如何将测试标记为不确定的,即存在但既不成功也不失败,例如因为它尚未实现?
我来自Node.js背景,例如在Mocha(Node.js的测试运行器)中,您可以定义一个没有实现的测试,然后Mocha将此测试标记为“pending”。
在Go中如何实现这一点?
(如果有任何区别的话,我正在使用go test
之上的gocheck。)
英文:
When writing tests in Go, how do I mark a test as inconclusive, i.e. as existent, but neither succeeding or failing, e.g. because it does not yet have an implementation?
I'm coming from a Node.js background, and e.g. in Mocha (a test-runner for Node.js) you can define a test without an implementation, and then Mocha marks this test as pending
.
How can you do this with Go?
(If it makes any difference, I am using gocheck on top of go test
.)
答案1
得分: 1
我很确定这不是你想要的,但我会为此使用跳过(skip)。
func TestTimeConsuming(t *testing.T) {
if testing.Short() {
t.Skip("在短模式下跳过测试。")
}
...
}
这可能是有争议的,但我认为测试不应该是不确定的。它们应该通过/失败或跳过。
英文:
I'm pretty sure this is not what you want but I'd use skip for this
func TestTimeConsuming(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
...
}
This is likely controversial but I don't think tests should be inconclusive. They should Pass/Fail or Skip.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论