Search code examples
gradlegroovyspock

Is there a concept of test suites in Gradle/Spock land?


Groovy/Gradle project here that uses Spock for unit testing.

Does Spock and/or Gradle support test suites or named sets of tests? For reasons outside the scope of this question, there are certain Spock tests (Specifications) that the CI server just can't run.

So it would be great to divide all my app's Spock tests into two groups:

  1. "ci-tests"; and
  2. "local-only-tests"

And then perhaps we could invoke them via:

./gradlew test --suite ci-tests

etc. Is this possible? If so, what does the setup/config look like?


Solution

  • You can annotate the tests that should not run in your CI server with the Spock annotation @IgnoreIf( ).

    See the documentation here: https://spockframework.github.io/spock/docs/1.0/extensions.html#_ignoreif

    All you need to do is let the CI server set an environment variable, and exclude the test class if that variable is set.

    Spock even have properties inside the closure to make it easy:

    @IgnoreIf({ sys.isCiServer })