如何在Go中编写待处理的测试

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

How To Write Pending Tests In Go

问题

有没有合法的方法来编写一个测试用例,我打算以后编写完整的测试函数?就像mochajs的待定测试一样?

英文:

Is there legitimate way to write down a test case for which I intent to write full test function later on? As like pending tests of mochajs?

答案1

得分: 13

包文档中描述了使用testing.(*T).Skip的示例:

>如果测试或基准测试不适用,可以调用T和B的Skip方法来跳过:
>
func TestTimeConsuming(t *testing.T) {
if testing.Short() {
t.Skip("在短模式下跳过测试。")
}
...
}

如果你使用go test命令时带上-v标志,将会打印出你提供给Skip方法的消息(在这个示例中,你还需要提供-short标志才能看到跳过的消息)。

英文:

The package docs describe such example with testing.(*T).Skip:

>Tests and benchmarks may be skipped if not applicable with a call to the Skip method of *T and *B:
>
func TestTimeConsuming(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
...
}

The message you provided for Skip will be printed if you launch go test with a -v flag (in this example you'll also need to provide -short flag to see the skip message).

huangapple
  • 本文由 发表于 2015年10月29日 00:24:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/33396376.html
匿名

发表评论

匿名网友

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

确定