Java Reference
In-Depth Information
Here I want to add an additional testing directory. For both the Java and Groovy plugins,
simply defining a source set name generates the proper tasks.
In the current build I add a source set called
integrationTest
:
sourceSets {
integrationTest
}
This causes Gradle to generate tasks called
compileIntegrationTestJava
,
com-
pileIntegrationTestGroovy
,
processIntegrationTestResources
, and
integrationTest-Classes
. The directory tree now includes src/integrationTest/
java, src/integrationTest/groovy, and src/integrationTest/resources.
For this source set I would like the compile and runtime dependencies to match their coun-
terparts in the regular test directory:
dependencies {
// ... Various libraries ...
integrationTestCompile configurations.testCompile
integrationTestRuntime configurations.testRuntime
}
As before, I'll use the
intTest
task, but now I need to configure it to have the proper
classpath and test directories. Here's the new version of the task:
task intTest(type: Test, dependsOn: jettyRun) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
jettyStop.execute()
}
The
testClassesDir
property points to the compiled test sources. The classpath is set
to the runtime classpath of the source set, which is simply the runtime classpath of the reg-
ular tests. I can now place integration tests into the src/integrationTest directory tree, and
they'll be executed at the proper time.
One final issue remains before presenting the integration tests. It's easy to create an HTTP
GET request: you convert the string URL to an instance of
java.net.URL
and then ac-
cess its
text
property, as shown previously. It's not as simple to create POST, PUT, and