向Gradle添加额外的测试套件 [英] Adding an additional test suite to Gradle
问题描述
我正在尝试将Gradle(1.4)添加到具有多个测试套件的现有项目中。位于 src / test / java
中的标准单元测试已成功运行,但我无法设置任务来运行位于 src中的JUnit测试/集成测试/ JAVA
。
当我运行 gradle intTest
时,我得到几个找不到符号
intTest
,以便它能运行我的JUnit集成测试?
build.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',名称:'hamcrest-all',版本:'1. +')
testCompile(group:'org.mockito',name:'mockito-all',version:'1. +')
testCompile(group:'org.springframework',name:'spring-test',version:'3.0.7.RELEASE')
$ b integrationCompile(group:'org.hamcrest',name:'hamcrest-all'); b
integrationCompile(group:'junit',name:'junit',version:'4. +') ,版本:'1. +')
integrationCompile(group:'org.mockito',name:'mockito-all',version:'1. +')
integrationCompile(group:'org。 springframework',version:'3.0.7.RELEASE')
}
任务intTest(type:Test){
testClassesDir = sourceSets.integration.output.classesDir
classpath + = sourceSets.integration.runtimeClasspath
}
详细信息: Gradle 1.4
解决方案:我没有为集成测试源集设置编译类路径(见下文)。在我的代码中,我将编译类路径设置为 sourceSets.test.runtimeClasspath
,以便我没有integrationCompile的重复依赖关系
sourceSets {
integrationTest {
java {
srcDir'src / integration-test / java'
资源{
srcDir'src / integration-test / resources'
}
compileClasspath + = sourceSets.main.runtimeClasspath
}
}集成sourceSet尚未配置其编译和运行时类路径。这就是为什么它无法从你的主要源代码集中找到这些类。您可以通过以下方式配置编译和运行时类路径: sourceSets {
integTest {
java .srcDir文件('src / integration-test / java')
resources.srcDir文件('src / integration-test / resources')
compileClasspath = sourceSets.main.output + configurations.integTest
runtimeClasspath = output + compileClasspath
}
}
I am attempting to add Gradle (1.4) to an existing project that has multiple test suites. The standard unit test located in src/test/java
ran successfully, but I am having trouble setting up a task to run the JUnit test located in src/integration-test/java
.
When I run gradle intTest
I get several cannot find symbol
errors for classes in src/main
. This leads me to believe that the dependencies are not set up correctly. How do I setup intTest
so that it will run my JUnit integration tests?
build.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
}
Details: Gradle 1.4
Solution: I had not set the compile classpath for the integration test source set (see below). In my I code I set the compile class path to sourceSets.test.runtimeClasspath
so that I don't have the duplicate dependencies for "integrationCompile"
sourceSets {
integrationTest {
java {
srcDir 'src/integration-test/java'
}
resources {
srcDir 'src/integration-test/resources'
}
compileClasspath += sourceSets.main.runtimeClasspath
}
}
解决方案 the "integration" sourceSet has not configured its compile and runtime classpath. That's why it can't find the classes from your main sourceset. you can configure the compile and runtime classpath in the following way:
sourceSets {
integTest {
java.srcDir file('src/integration-test/java')
resources.srcDir file('src/integration-test/resources')
compileClasspath = sourceSets.main.output + configurations.integTest
runtimeClasspath = output + compileClasspath
}
}
这篇关于向Gradle添加额外的测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!