integration-testing

command module
v0.0.0-...-eabd6fe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2025 License: Apache-2.0 Imports: 1 Imported by: 0

README

Integration Testing in Go

Problem: I want to write integration tests that require "components of integration" to be running. I want to write these tests in as similar a manner as my unit tests as possible. I don't want the integration tests to run during normal build/test cycles, (i.e. go test), but I would like to use Go's testing framework.

Running External Components

There are no actual external components to this example. If there were, then they would not need to be running during normal (unit) tests. And, the external components would need to be started, manually prior to running the integration tests

Solultion

The first line of each _test.go file contains a build tag, (// +build ...). That tag either sets, or inverts, (!integration) the 'integration' tag. When go test is run, any test case ('_test.go' file) with the flag set will NOT be run. Conversely, if go test is run with the --tags=integration flag, it will cause 'integration' tagged test cases to be run.

Any test cases not setting the integration flag will also be run when --tags=integration is added. In order to keep non-integraton tests from being run during integration tests, invert the flag as is done in 'main_test.go'.

Usage

Unit Tests:

go test -v ./...

Integration Tests:

go test -v --tags=integration ./...

References & Citations

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL