An integration testing plugin for Gradle.
This plugin uses Gradle as its build tool. To build the project, run the following.
./gradlew build
Apply the plugin to your project using:
apply plugin: "com.rocana.gradle.test.integration"
buildscript {
dependencies {
classpath "com.rocana.gradle:gradle-integration-test-plugin:some-version"
}
}
This plugin requires no configuration beyond applying the plugin. Once applied, the following changes are made to the project.
- The
javaplugin is applied. If it's already applied, Gradle will prevent it from being applied twice. - A new dependency configuration named
integrationTestis created that extends the standardtestconfiguration added by thejavaplugin. - A new source set named
integrationTestis created for Java files contained within the directorysrc/test/javawith an include restricted to the pattern**/*IT*.java. The compilation and runtime classpaths contain everything thetestsource set contains with the notable addition of the test classes, themselves. (See 6 below). - The
testsource set is modified to contain an exclude for the pattern used in theintegrationTestsource set. That is, any test class name containing the stringITwill not execute during thetesttask, and will execute during theintegrationTesttask (see below). - Tasks are created for the compilation, resource processing, and execution of
the integration tests. These tasks are named
compileIntegrationTestClasses,processIntegrationTestResources, andintegrationTest, respectively. - The
compileIntegrationTestClassestest is set to depend ontestClassesto ensure all test classes are compiled before the integration tests. This, combined with theintegrationTestdependency configuration, allows integration tests to reference classes from thetestsource set. - The
checktask is modified to depend on the newly addedintegrationTesttask. This means integration tests will run as part ofgradle checkbut notgradle test.
Summary:
- Put your integration tests in
src/test/javaand includeITsomewhere in the class name. You can reference bothmainandtestclasses. - To run your unit tests, use
gradle testas you normally would. - To run your integration tests, use
gradle integrationTest. - Your integration tests use the same dependencies as your
testdependencies, but you can add integration test-only dependencies using:dependencies { integrationTest "some.group:some-module:1.0.0" } - Integration tests will automatically run as part of
gradle buildbut you skip them by runninggradle build -x integrationTestjust as you would skip unit tests withgradle build -x test.