Integration tests, wildcard ignore tags

892 views Asked by At

I would like to separate my integration tests from the unit tests. I have read that I can do it including tags in the test file:

// +build integration

On the other hand, I select all the packages from my project by using wildcards ./...

Unfortunately, I have problems, tags are ignored because of the wildcard.

go test ./... -tags=integration

or

go test -tags=integration ./...

Do you have any solution or alternative to it?

2

There are 2 answers

0
ddrake12 On

Update 2021

This Just Works now! But I did run into an issue where the tags are ignored if there is a TestMain function in the file. So if you're having this issue now, check for that. For the record I run with:

go test -tags="all your tags here" -v -count=1 ./...

Hopefully this helps someone in the future

0
Maxim On

Within your integration tests you can use:

func Test_SomeIntegration(t *testing.T) {
    if testing.Short() {
      t.Skip("skipping test")
    }
    ...
}

And then pass -short flag to the go test command to skip integration tests:

go test -short ./...