Here’s a quick tip on how to skip long running tests in Go.
In your test function that you want to skip, add a t.Short()
boolean check.
For example:
1func TestLongRunning(t *testing.T) {
2 if t.Short() {
3 t.Skip("skip long running test")
4 }
5 // tests that will take a while to run
6 ...
7}
Then when you run go test
, simply provide a -short
flag to skip the test.
For example:
1$~ go test -v -short
You can confirm this behaviour by checking test output. You should see skipping long running test in short mode
message in the output.
For example:
1--- SKIP: TestLongRunningTest (0.00s)
2 main_test.go:27: skipping long running test in short mode
3PASS
4ok github.com/faizmokhtar/toytesting 0.385s
That’s it. Hope you’ll find this tip useful.
References:
- Go' testing Short documentation
- [Stack Overflow - Skip some tests with Go] (https://stackoverflow.com/questions/24030059/skip-some-tests-with-go-test)