How do I know I’m running within “go test”

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")
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)