I'm using java-test-fixtures
in combination with jvm-test-suite
. I'd like my testFixtures
to be available to both unit tests and my integrationTest
suite.
java-test-fixtures
adds testFixtures
as a dependency to the default unit test suite, along with compile-time and runtime transitive dependencies. What's the right way to add this to integrationTest
too?
The following works, but it seems a bit repetitive:
plugins {
id 'java'
id 'application'
id 'java-test-fixtures'
id 'jvm-test-suite'
}
testing {
suites {
integrationTest(JvmTestSuite) {
dependencies {
implementation sourceSets.testFixtures.output
}
configurations {
integrationTestCompileClasspath.extendsFrom testFixturesApi
integrationTestRuntimeClasspath.extendsFrom testFixturesRuntimeClasspath
}
}
}
}
I can also use testFixtures(project)
, but only if I declare the dependency in a top-level dependency block, with the top-level dependency block appearing after the test suite has been declared:
testing {
suites {
integrationTest(JvmTestSuite) {}
}
}
dependencies {
integrationTestImplementation testFixtures(project)
}
This works, with all the transitive dependencies set up correctly.
Curiously, I can't use testFixtures(project)
inside the test suite declaration - the following:
testing {
suites {
integrationTest(JvmTestSuite) {
dependencies {
implementation testFixtures(project)
}
}
}
}
...fails to evaluate.
Is there a preferred way to have a test suite depend upon testFixtures
?
CodePudding user response:
It sounds like you want to avoid repeating the configuration for the testFixturesApi
and testFixturesRuntimeClasspath
dependencies in the integrationTest
configuration. To do this, you can use the extendsFrom
method to extend the integrationTest
configuration from the testFixtures
configuration, like this:
testing {
suites {
integrationTest(JvmTestSuite) {
dependencies {
implementation sourceSets.textFixtures.output
}
configurations {
integrationTestCompileClasspath.extendsFrom testFixtures
integrationTestRuntimeClasspath.extendsFrom testFixtures
}
}
}
}
This will include the testFixturesApi
and testFixturesRuntimeClasspath
dependencies in the integrationTest
configuration, so you don't have to specify them explicitly.
CodePudding user response:
I hate to answer my own question! The cleanest solution right now appears to be to fully-qualify the testFixtures
function inside the test's dependencies
block:
integrationTest(JvmTestSuite) {
dependencies {
implementation project.getDependencies().testFixtures(project)
}
}