How do I add testFixures as a dependency of a JvmTestSuite with gradle

740 views Asked by At

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?

2

There are 2 answers

0
Ian Parkinson On BEST ANSWER

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)
  }
}
0
Steep On

This is currently the most succinct (Kotlin DSL),

dependencies {
    implementation(testFixtures(project(":project_name")))
}

It's possible the api changed since you posted the question since it's still being incubated.