I have seen several different test package naming strategies within Go and wanted to know what pros and cons of each are and which one I should use.
Strategy 1:
File name: github.com/user/myfunc.go
package myfunc
Test file name: github.com/user/myfunc_test.go
package myfunc
See bzip2 for an example.
Strategy 2:
File name: github.com/user/myfunc.go
package myfunc
Test file name: github.com/user/myfunc_test.go
package myfunc_test
import (
"github.com/user/myfunc"
)
See wire for an example.
Strategy 3:
File name: github.com/user/myfunc.go
package myfunc
Test file name: github.com/user/myfunc_test.go
package myfunc_test
import (
. "myfunc"
)
See strings for an example.
The Go standard library seems to use a mixture of strategy 1 and 2. Which of all three should I use? It's a pain appending package *_test
to my testing packages as it means I can't test my package private methods but maybe there is a hidden advantage I am not aware of?