我正在尝试向一个包添加一个示例,并通过示例运行该示例go test,但该示例永远不会运行.
例如,请参阅此要点:https://gist.github.com/85469ecc65bb5bb85857
要点有example_test.go:
package cow_test
import (
cow "gist.github.com/85469ecc65bb5bb85857"
)
func Example() {
cow.Poke()
}
Run Code Online (Sandbox Code Playgroud)
然而,当我运行这个:
# go test -v example_test.go
testing: warning: no tests to run
PASS
ok command-line-arguments 0.002s
Run Code Online (Sandbox Code Playgroud)
但是stdlib的其他软件包工作得很好:
# cd /usr/lib/go/src/errors
# go test -v example_test.go
=== RUN: Example
--- PASS: Example (0.00s)
PASS
ok command-line-arguments 0.002s
Run Code Online (Sandbox Code Playgroud)
我的例子出了什么问题?
Cer*_*món 16
从文档:
没有输出注释的示例函数被编译但不执行.
添加输出注释:
func Example() {
junk.Poke()
// Output: MOOOO!
}
Run Code Online (Sandbox Code Playgroud)