patterngoCritical
Skip some tests with go test
Viewed 0 times
withsometeststestskip
Problem
Is it possible to skip/exclude some tests from being run with
I have a fairly large amount of integration type tests which call a REST service written as standard go tests, and run with
I know about
Another option would be to not commit the tests which don't run in the same branch, but it would be easier if I could just specify what to exclude.
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 it's 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 don't 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 don't run in the same branch, but it would be easier if I could just specify what to exclude.
Solution
Testing package has
You could then set the environment variable or run
Another approach would be to use short mode. Add the following guard to a test
and then execute your tests with
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 -shortCode Snippets
func skipCI(t *testing.T) {
if os.Getenv("CI") != "" {
t.Skip("Skipping testing in CI environment")
}
}
func TestNewFeature(t *testing.T) {
skipCI(t)
}if testing.Short() {
t.Skip("skipping testing in short mode")
}Context
Stack Overflow Q#24030059, score: 202
Revisions (0)
No revisions yet.