我想在我的 Gradle 构建(版本 1.0)中添加集成测试。它们应该与我的正常测试分开运行,因为它们需要将 web 应用程序部署到 localhost(它们测试该 web 应用程序)。测试应该能够使用我的主要源集中定义的类。我该如何做到这一点?
最佳答案
2021 年更新:
8 年来发生了很多变化。 Gradle 仍然是一个很棒的工具。现在,文档中有一个完整的部分专门用于配置集成测试。我推荐你read the docs现在。
原答案:
我花了一段时间才弄明白,而且在线资源不是很好。所以我想记录下我的解决方案。
这是一个简单的 gradle 构建脚本,除了 main 和 test 源集之外还有一个 intTest 源集:
apply plugin: "java"
sourceSets {
// Note that just declaring this sourceset creates two configurations.
intTest {
java {
compileClasspath += main.output
runtimeClasspath += main.output
}
}
}
configurations {
intTestCompile.extendsFrom testCompile
intTestRuntime.extendsFrom testRuntime
}
task intTest(type:Test){
description = "Run integration tests (located in src/intTest/...)."
testClassesDir = project.sourceSets.intTest.output.classesDir
classpath = project.sourceSets.intTest.runtimeClasspath
}
https://stackoverflow.com/questions/11581419/