- Integration Testing
- Filenames
- main_integration_test.go - meh
- package/integration_test.go - Better
- Give it build tag of integration.
- package/integration_foo_test.go
- package/file_integration_test.go - hmmm.
- Use
-check.f
to check for code patternsgo test ... -check.f '.*Unit.*' go test ... -check.f '.*Integration.*'
- Advantages
- Can mingle test code in the same directories
- Disadvantages
- If you don't use the right pattern in your code, the test might be skipped
- Advantages
- Use
-short
flaggo test -short
to run unit tests only.func TestPostgresVersionIntegration(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") } ... }
- Running without
-short
runs everything. - Simple and used in standard library.
- Not as flexible.
- Use
-run
flag- Naming Convention
TestUnitFoo
go test -run 'Unit'
TestIntegrationFoo
go test -run 'Integration'
- Can mix and match with integrations
- Naming Convention
- Using build flags
// +build integration
go test --tags=integration
- Test configuration
- Use global flags
var fooAddr = flag.String(...) func TestToo(t *testing.T) { f, err := foo.Connect(*fooAddr) // ... }
- Use shared package
testing/integration/integration.go
- Use global flags
- Filenames
Created
March 25, 2020 17:18
-
-
Save dhulihan/74d6c8c2ff24e66da61956c55b3d2477 to your computer and use it in GitHub Desktop.
integration testing in go
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment