{
  "slug": "Run-test-case-in-Golnag-with--env-file-520616cbb54a",
  "title": "Run test case in Golnag with .env file",
  "subtitle": "You can add following snippets to VSCode settings.json to specify environment variables just for go test runs:",
  "excerpt": "You can add following snippets to VSCode settings.json to specify environment variables just for go test runs:",
  "date": "2023-01-16",
  "tags": [
    "Go",
    "Testing"
  ],
  "readingTime": "1 min",
  "url": "https://medium.com/@mobinshaterian/run-test-case-in-golnag-with-env-file-520616cbb54a",
  "hero": null,
  "content": [
    {
      "type": "heading",
      "level": 2,
      "text": "Run test case in Golnag with .env file"
    },
    {
      "type": "paragraph",
      "html": "You can add following snippets to VSCode <code>settings.json</code> to specify environment variables just for <code>go test</code> runs:"
    },
    {
      "type": "code",
      "lang": "json",
      "code": "{\n  \"go.testEnvVars\": {\n    \"MY_VAR\": \"my value\"\n  }\n}"
    },
    {
      "type": "paragraph",
      "html": "Or using dedicated file (in my example called&nbsp;<code>.env</code> in root of project workspace) containing the environment variables in <code>MY_VAR=\"my value\"</code> format with one variable per line:"
    },
    {
      "type": "code",
      "lang": "json",
      "code": "{\n  \"go.testEnvFile\": \"${workspaceFolder}/.env\"\n}"
    },
    {
      "type": "code",
      "lang": "json",
      "code": "{\n  \"go.testEnvFile\": \"${workspaceFolder}/.env\",\n  \"go.testTimeout\": \"300s\",\n  \"go.testFlags\": [\n    \"-count=1\"\n  ]\n}"
    },
    {
      "type": "paragraph",
      "html": "<a href=\"https://stackoverflow.com/questions/52948250/how-do-i-automatically-clean-the-go-cache-in-visual-code-before-running-tests\" target=\"_blank\" rel=\"noreferrer noopener\">https://stackoverflow.com/questions/52948250/how-do-i-automatically-clean-the-go-cache-in-visual-code-before-running-tests</a>"
    }
  ]
}
