You’d probably like to make the integrationTestImplementation configuration extend the testImplementation configuration – just like testImplementation already extends implementation by default. See also the docs on configuration inheritance.
Here’s a self-contained example (tested with Gradle 7.3.2):
plugins {
`java-library`
}
repositories {
mavenCentral()
}
testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter()
dependencies {
implementation("org.assertj:assertj-core:3.21.0")
}
}
val integrationTest by registering(JvmTestSuite::class) {
dependencies {
// TODO add any integration test only dependencies here
}
}
}
}
// Here’s the bit that you’re after:
val integrationTestImplementation by configurations.getting {
extendsFrom(configurations.testImplementation.get())
}
If you run ./gradlew dependencies --configuration integrationTestRuntimeClasspath with the configuration inheritance configured, then you’ll get the following output (abbreviated):
integrationTestRuntimeClasspath - Runtime classpath of source set 'integration test'.
+--- org.junit.jupiter:junit-jupiter:5.7.2
| +--- org.junit:junit-bom:5.7.2
| | …
| +--- org.junit.jupiter:junit-jupiter-api:5.7.2
| | …
| +--- org.junit.jupiter:junit-jupiter-params:5.7.2
| | …
| \--- org.junit.jupiter:junit-jupiter-engine:5.7.2
| …
\--- org.assertj:assertj-core:3.21.0
However, if you run the same command without the configuration inheritance, then you’ll get the following output (abbreviated) – note the missing org.assertj:assertj-core:3.21.0 dependency:
integrationTestRuntimeClasspath - Runtime classpath of source set 'integration test'.
\--- org.junit.jupiter:junit-jupiter:5.7.2
+--- org.junit:junit-bom:5.7.2
| …
+--- org.junit.jupiter:junit-jupiter-api:5.7.2
| …
+--- org.junit.jupiter:junit-jupiter-params:5.7.2
| …
\--- org.junit.jupiter:junit-jupiter-engine:5.7.2
As requested in the answer comments, here’s additionally one way of making a test data class from the unit test suite available for integration testing:
sourceSets.named("integrationTest") {
java {
val sharedTestData = project.objects.sourceDirectorySet("testData",
"Shared test data")
sharedTestData.srcDir("src/test/java")
sharedTestData.include("com/example/MyData.java")
source(sharedTestData)
}
}