我一直在尝试在gradle项目中配置spock。因此,通过以下配置,它可以解决问题。
应用插件:“groovy”
我的测试用例位于src/test/groovy
文件夹中。这个工作正常,我能够运行测试用例。
但是,我想将集成测试分成一个单独的文件夹结构src/itest/groovy
。
为此,我添加了以下内容:
sourceSets {
itest {
srcDir file('src/itest/groovy')
}
resourceDir ..
compileClassPath ..
}
configurations {
itestCompile.extendsfrom testCompile
}
由于组织机构的限制,我无法在此处复制整个代码。但是我确实尝试了所有可以在线获得的变体,但没有成功!!
我总是得到错误:
The task compileItestGroovy was not found in the project.
我做了一些研究,默认情况下该任务是由groovy插件添加的。仍然找不到任务,我的构建陷入了困境。如果您能帮我解决这个问题,那就太好了。
P.S该项目还具有其他插件,例如java,因为源代码位于java中。
运行命令-./gradlew clean build
Gradle 版本-2.2.1
我在家用计算机上尝试使用gradle 3.5版进行类似的设置,并且工作正常。
最佳答案
给定以下build.gradle
文件:
apply plugin: 'groovy'
repositories {
jcenter()
}
sourceSets {
integration {
groovy {
compileClasspath += main.output
runtimeClasspath += main.output
srcDirs = ['src/integration/groovy']
}
resources.srcDir file('src/integration/resources')
}
}
configurations {
// By default, integration tests have the same dependencies as standard tests
integrationCompile.extendsFrom testCompile
integrationRuntime.extendsFrom testRuntime
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.12'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
// This is only available for the integration tests
integrationCompile 'com.github.ben-manes.caffeine:caffeine:2.5.5'
}
tasks.create('integrationTest', Test) {
dependsOn 'compileIntegrationGroovy'
group = 'Verification'
description = 'Runs the integration tests'
// GRADLE 2.2
testClassesDir = sourceSets.integration.output.classesDir
// GRADLE 3.5
// testClassesDirs = sourceSets.integration.output.classesDirs
classpath = sourceSets.integration.runtimeClasspath
}
tasks.findByName('check').dependsOn 'integrationTest'
您应该能够将集成测试保留在
src/integration/groovy
中,并且./gradlew check
将同时运行标准测试和集成测试
关于gradle - 无法在单独的sourceSet中配置Gradle中的Spock测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46223738/