在几篇博客文章后,我尝试在gradle中创建一个单独的源文件夹进行集成测试。我还想在我的integrationTest任务中添加一些additinal(arquillian)依赖项,但是似乎忽略了integrationTestCompile,并且我得到了一个编译错误,其中没有解析附加依赖。当我将dependecy更改为testCompile时,它可以正常工作。为什么会如此以及如何改变它?我的简单测试类:
//compilation fails with [Static type checking] - The variable [ArquillianSputnik] is undeclared
@TypeChecked
@RunWith(ArquillianSputnik)
class TestSpec extends Specification {
}
和gradle.build:
apply plugin: 'groovy'
apply plugin: 'war'
war.dependsOn 'native2ascii'
task native2ascii << {
ant.delete() {
fileset(dir: "${processResources.destinationDir}") {
include(name: '*.properties')
}
}
ant.native2ascii(src: 'src/main/resources/',
dest: "${processResources.destinationDir}",
includes: '**/*.properties',
encoding: 'UTF-8')
}
repositories {
mavenCentral()
maven {
url 'http://repository.jboss.org/nexus/content/groups/public'
}
mavenLocal()
}
sourceSets.main.java.srcDirs = []
sourceSets.main.groovy.srcDirs += ["src/main/java"]
sourceSets {
integrationTest {
groovy.srcDir file('src/integration-test/groovy')
resources.srcDir file('src/integration-test/resources')
compileClasspath = sourceSets.main.output + configurations.testCompile
runtimeClasspath = output + compileClasspath + configurations.testRuntime
}
}
dependencies {
//(...) non-test dependencies cut out for clarity
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'cglib:cglib-nodep:2.2.2'
testCompile 'org.objenesis:objenesis:1.2'
//when integrationTestCompile is changed to testCompile the compilation works and the test is executed
integrationTestCompile 'org.jboss.arquillian.spock:arquillian-spock-container:1.0.0.Beta3'
integrationTestCompile 'org.jboss.arquillian.graphene:graphene-webdriver:2.0.3.Final'
integrationTestCompile 'org.jboss.as:jboss-as-arquillian-container-managed:7.2.0.Final'
}
task integrationTest(type: Test, dependsOn: 'test') {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
}
check.dependsOn 'integrationTest'
答案 0 :(得分:4)
首先,您希望添加到编译和运行时类路径而不是替换它们。这实际上只意味着使用+=
运算符而不是=
运算符。此外,您实际上只想添加其他源集输出,我们将分别处理配置。
compileClasspath += sourcesets.main.output + sourcesets.test.output
runtimeClasspath += sourcesets.main.output + sourcesets.test.output
接下来,我们要配置集成测试配置。通常,这只是意味着让它们扩展测试并编译它们,以便它们也包含所有这些依赖项。
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}