Here is my directory hierarchy:
/
|-- main.go // package main
|-- main_test.go
|-- pkg1 // package pkg1
|-- pkg1_test.go
I have some utility functions for tests only in pkg1_test.go
. main.go
imports pkg1
. Now I want to use these functions in my main_test.go
. After searching I found two possible solutions, but both of them have some drawbacks:
- Move these functions into
pkg1.go
. However these functions might be contained in binaries generated bygo build
. - Move these functions into a separate
testutility
package, then import it in*_test.go
manually. The problem is that these functions use some internal methods inpkg1
.
So I was wondering whether there is a better solution to this problem.
Aucun commentaire:
Enregistrer un commentaire