Run test case in Golnag with .env file

You can add following snippets to VSCode settings.json to specify environment variables just for go test runs:

json
{
  "go.testEnvVars": {
    "MY_VAR": "my value"
  }
}

Or using dedicated file (in my example called .env in root of project workspace) containing the environment variables in MY_VAR="my value" format with one variable per line:

json
{
  "go.testEnvFile": "${workspaceFolder}/.env"
}
json
{
  "go.testEnvFile": "${workspaceFolder}/.env",
  "go.testTimeout": "300s",
  "go.testFlags": [
    "-count=1"
  ]
}

https://stackoverflow.com/questions/52948250/how-do-i-automatically-clean-the-go-cache-in-visual-code-before-running-tests