Gradle 集成测试和测试固件

3

我使用的是Gradle 7.4.2,所以我决定将测试分成适当的单元测试和集成测试。我将一个类从src/test/java/com/example移动到src/integrationTest/java/com/example,并开始添加缺失的依赖。

问题在于我找不到如何使用:project-with-fixture的testFixtures。在integrationTest中有没有办法做到这一点?

我有以下依赖项:

testImplementation project(':other-project')
testImplementation project(':project-with-fixture')
testImplementation testFixtures(project(':project-with-fixture'))
testImplementation project(':common')
testImplementation "com.google.guava:guava:${com_google_guava_version}"

以下是新的build.gradle部分:

testing {
    suites {
        integrationTest(JvmTestSuite) {
            dependencies {
                implementation project
                implementation project(':other-project')
                implementation project(':project-with-fixture')
//                testImplementation testFixtures(project(':project-with-fixture'))
                implementation project(':common')
                implementation "com.google.guava:guava:${com_google_guava_version}"
            }

            targets {
                all {
                    testTask.configure {
                        shouldRunAfter(test)
                    }
                }
            }
        }
    }
}
tasks.named('check') {
    dependsOn testing.suites.integrationTest
}
1个回答

0

当使用当前的Gradle版本7.5.1时,您可以这样做:

testing {
  suites {
    integrationTest(JvmTestSuite) {
      dependencies {
        implementation(project.dependencies.testFixtures(project(':project-with-fixture')))
        ...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接