我正在使用星云测试为我的第一个Gradle插件编写集成测试。
我现在正在进行一项测试,需要从我的资源中复制一个或多个文件"进入临时项目目录。 " copyResources()"呼叫失败,因为它说"来自"目录不在类路径中。
具体来说,它失败了:
java.lang.RuntimeException: Could not find classpath resource: src/integTest/resources
at nebula.test.IntegrationSpec.copyResources(IntegrationSpec.groovy:189)
at com.att.opnfv.yang.gradle.YangPluginIntegSpec.process Yang module with simple type reference and imported file for type(YangPluginIntegSpec.groovy:227)
这是我" build.gradle"的相关部分。文件:
buildscript {
repositories {
jcenter()
mavenCentral()
}
}
apply plugin: 'groovy'
apply plugin: 'java-gradle-plugin'
apply plugin: 'maven'
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile "org.codehaus.groovy:groovy-all:2.3.9"
compile gradleApi()
compile "commons-io:commons-io:2.4"
testCompile("org.spockframework:spock-core:1.0-groovy-2.3") {
exclude group: "org.codehaus.groovy"
}
}
sourceCompatibility = 1.7
group = 'com.att.opnfv.yang'
version = '1.0.0-SNAPSHOT'
tasks.withType(Test) {
testLogging {
exceptionFormat "full"
}
}
sourceSets {
integTest {
groovy.srcDir file("src/integTest/groovy")
resources.srcDir file("src/integTest/resources")
runtimeClasspath = output + compileClasspath // I thought this would do it
}
}
dependencies {
integTestCompile sourceSets.main.output
integTestCompile configurations.testCompile
integTestCompile sourceSets.test.output
integTestRuntime configurations.testRuntime
testCompile( 'com.netflix.nebula:nebula-test:2.2.1' ) {
exclude module: 'groovy-all'
}
}
task integTest(type: Test) {
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath
outputs.upToDateWhen { false }
}
check.dependsOn -= integTest
这是我的Spec方法,它有" copyResources()"拨打:
def 'process Yang module with simple type reference and imported file for type'() {
when:
directory("src/main/yang")
File yangFile = createFile("src/main/yang/base.yang")
yangFile << '''
module base {
namespace "base";
prefix base;
import ietf-inet-types {prefix inet; revision-date "2010-09-24";}
grouping "group" {
leaf ip-base {
type inet:ip-version;
}
}
}
'''.stripIndent()
directory("yangImports")
copyResources("src/integTest/resources", "yangImports") // line 227
buildFile << applyPlugin(YangPlugin)
buildFile << """
configurations {
yangImports
}
dependencies {
yangImports fileTree(dir: "yangImports", include: "*.yang")
}
yang {
yangFilesConfiguration "yangImports"
inspectDependencies true
yangFilesRootDir 'src/main/yang'
generator {
generatorClassName = 'com.att.opnfv.yang.generator.MockCodeGenerator'
outputDir = 'build/gen'
}
}
""".stripIndent()
ExecutionResult result = runTasksWithFailure('build')
then:
!result.wasUpToDate("yangGenerate")
result.standardError.contains("Imported module ietf-inet-types not found")
}
我错过了什么?
更新:
我对配置类路径与&#34; copyResources&#34;中引用的路径之间的关系感到困惑。我创建了&#34; src / integTest / resources / yang&#34;,将一个文件复制到该新文件夹中,然后将引用更改为:
copyResources("yang", "yangImports")
这是有效的,或者至少它已经解决了这个问题,所以我可以达到我的下一个障碍,但那不是Gradle /星云测试问题。
答案 0 :(得分:0)
我的错误是引用&#34; src / integTest / resources&#34;在&#34; copyResources&#34;呼叫。该文件夹已在类路径中。我需要引用的是&#34; src / integTest / resources&#34;的INSIDE文件夹。一旦我这样做,它运作良好。