How do I mark a test as inconclusive in Go?

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

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.

huangapple
  • 本文由 发表于 2016年4月13日 13:56:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/36589747.html
匿名

发表评论

匿名网友

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

确定