joriszwart.nl

I code dreams™

Running Go tests in Visual Studio with CGO

CGO Golang Mingw Tests Visual Studio Code

Problem

I had some trouble using go-sqlite3 while running tests in Visual Studio Code and the Go-extension. The Go compiler doesn't adhere to the environment variables CC and CGO_ENABLED in launch.json.

Solution

Open the global settings.json using the Command Palette (CTRL + SHIFT + P) and add:

"go.testEnvVars": {
  "CGO_ENABLED": "1",
  "CC": "x86_64-w64-mingw32-gcc.exe"
}

This shows using the Mingw (installed using Cygwin) compiler as well.