首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >星云测试无法在copyResources类路径中找到资源dir

星云测试无法在copyResources类路径中找到资源dir
EN

Stack Overflow用户
提问于 2015-03-30 23:07:09
回答 1查看 311关注 0票数 0

我正在用星云测试为我的第一级插件编写集成测试。

我现在正在进行一个测试,它需要将一个或多个文件从我的“资源”复制到临时项目目录中。"copyResources()“调用失败,因为它说"from”目录不在类路径中。

具体来说,它在这方面失败了:

代码语言:javascript
复制
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“文件的相关部分:

代码语言:javascript
复制
    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()“调用:

代码语言:javascript
复制
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")
}

我遗漏了什么?

更新

我对配置类路径与"copyResources“中引用的路径之间的关系感到困惑。我创建了"src/integTest/resources/yang",将一个文件复制到那个新文件夹中,然后将引用更改为:

代码语言:javascript
复制
copyResources("yang", "yangImports")

这起了作用,或者至少它通过了那个问题,这样我就能碰到下一个障碍了,但这不是一个分级/星云测试问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-31 17:06:52

我的错误是在"copyResources“调用中引用"src/integTest/resources”。那个文件夹已经在类路径中了。我需要引用的是"src/integTest/resources“中的文件夹。一旦我这么做了,一切都很顺利。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29357882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档