Skip tests conditionally in Go by adding a t.Skip() call inside your test function when a specific condition is met. This stops the test execution immediately and marks it as skipped rather than failed.
func TestExample(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping test on Windows")
}
// Test logic continues here
}
Alternatively, use build tags to exclude entire test files from compilation on specific platforms. Add //go:build !windows at the top of your test file to skip it on Windows.