Add //go:build integration to test files and run go test -tags=integration to execute them.
Use build tags in your test file header to exclude it from standard builds and include it only when running go test with the integration tag.
//go:build integration
package mypackage
func TestIntegration(t *testing.T) {
// Test code here
}
Run the tests with:
go test -tags=integration ./...
Build tags act like switches that tell Go to include or ignore specific files based on conditions. You use them for integration tests to keep your regular unit tests fast by skipping heavy tests that need external services unless you explicitly ask for them. Think of it like a 'debug mode' switch that only runs when you flip it on.