Separate integration tests
suggest changeA 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 (
"testing"
)
func TestThatRequiresNetworkAccess(t *testing.T) {
t.Fatal("It failed!")
}
Those tests will not be compiles unless you run tests with go test -tags "integration"
.
Results:
$ go test
? bitbucket.org/yourname/yourproject [no test files]
$ go test -tags "integration"
--- FAIL: TestThatRequiresNetworkAccess (0.00s)
main_test.go:10: It failed!
FAIL
exit status 1
FAIL bitbucket.org/yourname/yourproject 0.003s
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents