我正在尝试通过gradle文件运行我的junit测试,但构建成功但不运行任何测试。这就是我的gradle文件的样子:
apply plugin: 'java'
// Creating a new sourceSet because you should move your integration tests to a separate directory.
sourceSets {
test {
java.srcDirs = ['src/integration-test/java']
}
integrationTest {
java.srcDirs = ['src/integration-test/java']
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}
task integrationTest(type: Test, description: 'Runs the integration tests', group: 'Verification') {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
}
运行任务集成测试后,构建成功运行但不运行任何测试。有谁知道为什么?
答案 0 :(得分:1)
不知道您想要做什么:将完全移动测试类的集成测试分开到其他文件夹,但我认为您需要包含测试配置的依赖项,如下所示:
configurations {
integrationCompile.extendsFrom testCompile
integrationRuntime.extendsFrom testRuntime
}
例如集成测试配置:
sourceSets {
test {
java.srcDirs = ['src/test/java']
}
integration {
java.srcDirs = ['src/integration/java']
resources.srcDir 'src/integration/resources'
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
}
}
configurations {
integrationCompile.extendsFrom testCompile
integrationRuntime.extendsFrom testRuntime
}
task integration(type: Test, group: 'Verification') {
testClassesDir = sourceSets.integration.output.classesDir
classpath = sourceSets.integration.runtimeClasspath
}
如果您只想在其他文件夹(src/integration-test/java
)中移动测试并使用test
任务运行它们,则可以使用以下配置:
sourceSets {
test {
java.srcDirs = ['src/integration-test/java']
}
}