Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip some tests with go test

Tags:

testing

go

Is it possible to skip/exclude some tests from being run with go test?

I have a fairly large amount of integration type tests which call a rest service written as standard go tests, and run with go test. When a new feature is developed its sometimes useful to be able to skip some of the tests, for example if the new feature is not yet deployed on the testing server and I still want to run all the existing tests (except those new ones which tests the new feature).

I know about -run, but I dont want to specify all tests I want to run, that would be a long list. At the same time I have not been able to write a regex for excluding tests.

Another option would be to not commit the tests which dont run in the same branch, but it would be easier if I could just specify what to exclude.

like image 356
viblo Avatar asked Jun 04 '14 05:06

viblo


1 Answers

Testing package has SkipNow() and Skip() methods. So, an individual test could be prepended with something like this:

func skipCI(t *testing.T) {   if os.Getenv("CI") != "" {     t.Skip("Skipping testing in CI environment")   } }  func TestNewFeature(t *testing.T) {   skipCI(t) } 

You could then set the environment variable or run CI=true go test to set CI as a command-local variable.

Another approach would be to use short mode. Add the following guard to a test

if testing.Short() {   t.Skip("skipping testing in short mode") } 

and then execute your tests with go test -short

like image 158
Vadym Tyemirov Avatar answered Oct 13 '22 04:10

Vadym Tyemirov