Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 428
smeeb Avatar asked Feb 24 '16 21:02

smeeb


People also ask

Does Spock run tests in parallel?

By default, Spock runs tests sequentially with a single thread. As of version 2.0, Spock supports parallel execution based on the JUnit Platform. To enable parallel execution set the runner.

How do I add dependency to Spock?

Setting Up Dependencies We can generate a new dependency for the libraries we want using ⌘N / Alt+Insert in the build. gradle file and then choosing “Add Maven artifact dependency”. We can search for org. spockframework in the artifact search, and add the latest version of the spock-core library.


2 Answers

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 })

like image 184
Jacob Aae Mikkelsen Avatar answered Oct 29 '22 12:10

Jacob Aae Mikkelsen


I would set up a submodule my-app-ci-test, with the following in build.gradle:

test {
    enabled = false
}
task functionalTest(type: Test) {
}

Then you place your tests in src/test/groovy and run ./gradlew functionalTest.

Alternatively, you could include them in the same module and configure the test and functionalTest tasks with includes / excludes

test {
    exclude '**/*FunctionalTest.groovy'
}
task functionalTest(type: Test) {
    include '**/*FunctionalTest.groovy'
}
like image 27
davidnortonjr Avatar answered Oct 29 '22 13:10

davidnortonjr