我在 Go 中看到了几种不同的测试包命名策略,想知道每种策略的优缺点以及我应该使用哪一种。
策略一:
文件名:github.com/user/myfunc.go
package myfunc
测试文件名:github.com/user/myfunc_test.go
package myfunc
See bzip2 http://golang.org/src/pkg/compress/bzip2/bzip2_test.go举个例子。
策略2:
文件名:github.com/user/myfunc.go
package myfunc
测试文件名:github.com/user/myfunc_test.go
package myfunc_test
import (
"github.com/user/myfunc"
)
See wire https://github.com/btcsuite/btcd/blob/master/wire/msgtx_test.go举个例子。
策略3:
文件名:github.com/user/myfunc.go
package myfunc
测试文件名:github.com/user/myfunc_test.go
package myfunc_test
import (
. "myfunc"
)
See strings http://golang.org/src/pkg/strings/search_test.go举个例子。
Go 标准库似乎混合使用了策略 1 和 2。我应该使用这三种策略中的哪一种?这是一种痛苦的附加package *_test
我的测试包,因为这意味着我无法测试我的包私有方法,但也许有一个我不知道的隐藏优势?