Separate integration tests

suggest change

A common use case for build tags is separating regular unit tests from integration tests that require external resources, like a database or network access.

To do this, add a custom build constraint to the top of the test file:

// +build integration

package main

import (

func TestThatRequiresNetworkAccess(t *testing.T) {
    t.Fatal("It failed!")

Those tests will not be compiles unless you run tests with go test -tags "integration".


$ go test
?    [no test files]
$ go test -tags "integration"
--- FAIL: TestThatRequiresNetworkAccess (0.00s)
        main_test.go:10: It failed!
exit status 1
FAIL    0.003s

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents