skip to content
Alvin Lucillo

Integration test in pipeline

/ 1 min read

💻 Tech

Instead of using go build tags, you can skip integration tests by using environment variables. For example, if you’re using TestMain(m *testing.M), you can use this condition before m.Run():

testIntegration := os.Getenv("TEST_INTEGRATION")
// To run integration test, use with TEST_INTEGRATION=true go test ./integration_test -v
if testIntegration != "true" {
    log.Println("Skipping integration tests")
    os.Exit(0)
}

Why use this instead of build tags? Using build tags make integration tests not discoverable during build. If you have dependencies change, VS Code won’t detect if there are syntax errors with your integration tests. You will know there are errors when you run the tests in CI/CD or locally. To avoid this, you can just specify a flag, so go test won’t run these integration tests. To run integration tests, for example under a specific pipeline step in CI/CD, just add the flag like provided above.