I want to check if codes are running for the go test
,so that I could make some configurations.
Is there any function to do that? Like:
runtime.IsBei
Just specify that you run a test in test's init
. For example, in pkg.go:
package pkg
var isTesting = false
// ...
And in pkg_test.go:
package pkg
func init() {
isTesting = true
}
// ...
This technique can be used not just with bool
s but with any data or function. If you have some variable in your package (in your case, a configuration variable), you can just override it in init
.