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:
ci-tests
"; andlocal-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?
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.
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.
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 })
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'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With