The testing package modifies the global environment when loaded: it registers a lot of command-line flags. So, we can check if these flags are registered:
func init() {
if flag.Lookup("test.v") == nil {
fmt.Println("normal run")
} else {
fmt.Println("run under go test")
}
}