如何在测试中运行示例?

时间:2016-09-14 01:08:15

标签: testing go

我正在尝试在测试中运行示例。 但运行后会显示警告。 testing: warning: no tests to run

此示例代码包含评论// Output comment.

func ExampleMethod1() {
    fmt.Printf("result: %x", Method1())
    // Output: xxxx
}

有什么问题?运行测试时,我执行了这样的操作。 go test -v xxxx_test.go

感谢。

哈利

1 个答案:

答案 0 :(得分:1)

在这篇文章之后,我发现了它。

我的xxx_test.go文件根本不包含Testxxx func。 xxx_test.go火灾需要它至少一个。 除了Example之外添加Testxxx func之后,示例代码工作了!

谢谢!