我正在尝试将 Gradle (1.4) 添加到具有多个测试套件的现有项目中。位于 中的标准单元测试src/test/java
运行成功,但我在设置任务以运行位于src/integration-test/java
.
当我运行时,gradle intTest
我cannot find symbol
在src/main
. 这使我相信依赖项设置不正确。如何设置intTest
以便它运行我的 JUnit 集成测试?
构建.gradle
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_6
sourceSets {
integration {
java {
srcDir 'src/integration-test/java'
}
resources {
srcDir 'src/integration-test/resources'
}
}
}
dependencies {
compile(group: 'org.springframework', name: 'spring', version: '3.0.7')
testCompile(group: 'junit', name: 'junit', version: '4.+')
testCompile(group: 'org.hamcrest', name: 'hamcrest-all', version: '1.+')
testCompile(group: 'org.mockito', name: 'mockito-all', version: '1.+')
testCompile(group: 'org.springframework', name: 'spring-test', version: '3.0.7.RELEASE')
integrationCompile(group: 'junit', name: 'junit', version: '4.+')
integrationCompile(group: 'org.hamcrest', name: 'hamcrest-all', version: '1.+')
integrationCompile(group: 'org.mockito', name: 'mockito-all', version: '1.+')
integrationCompile(group: 'org.springframework', name: 'spring-test', version: '3.0.7.RELEASE')
}
task intTest(type: Test) {
testClassesDir = sourceSets.integration.output.classesDir
classpath += sourceSets.integration.runtimeClasspath
}
详细信息: Gradle 1.4
解决方案:我没有为集成测试源集设置编译类路径(见下文)。在我的 I 代码中,我将编译类路径设置为,sourceSets.test.runtimeClasspath
这样我就没有“integrationCompile”的重复依赖项
sourceSets {
integrationTest {
java {
srcDir 'src/integration-test/java'
}
resources {
srcDir 'src/integration-test/resources'
}
compileClasspath += sourceSets.main.runtimeClasspath
}
}