Gradle抱怨缺少初始集成测试结构的“setupMethod”

时间:2015-03-24 20:28:39

标签: groovy gradle spock nebula-test

我正在编写我的第一个Gradle插件。默认构建工作正常,包括少量单元测试。我现在正在尝试使用nebula.test建立集成测试基础架构。

我创建了一个空集成测试类,以及build.gradle中的设置来配置" integTest"任务和相关的源集和依赖项。我在网上和github上的现有插件中使用了几个例子来指导我。

在我展示我的代码之前,这是我得到的错误:

  

groovy.lang.MissingPropertyException:没有这样的属性:类的setupMethod:org.spockframework.runtime.model.SpecInfo   可能的解决方案:setupMethods

这是我的" build.gradle"文件:

    buildscript {
        repositories {
            jcenter()
            mavenCentral()
        }
    }

    apply plugin: 'groovy'
    apply plugin: 'java-gradle-plugin'
    apply plugin: 'maven'

    repositories {
        mavenCentral()
        jcenter()
        maven { url "http://oss.sonatype.org/content/repositories/releases/" }
        maven { url "http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot" }
        maven { url "http://nexus.opendaylight.org/content/repositories/opendaylight.release" }
    }

    dependencies {
        compile "org.codehaus.groovy:groovy-all:2.3.9"
        compile gradleApi()
        compile "org.opendaylight.yangtools:yang-parser-impl:0.7.0-SNAPSHOT"
        compile "org.opendaylight.yangtools:binding-java-api-generator:0.7.0-SNAPSHOT"
        compile "org.opendaylight.yangtools:binding-generator-api:0.7.0-SNAPSHOT"
        compile "org.opendaylight.yangtools:binding-generator-impl:0.7.0-SNAPSHOT"
        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'

    sourceSets {
        integTest {
            groovy.srcDir file("src/integTest/groovy")
            resources.srcDir file("src/integTest/resources")
        }
    }

    dependencies {
        integTestCompile sourceSets.main.output
        integTestCompile configurations.testCompile
        integTestCompile sourceSets.test.output
        integTestRuntime configurations.testRuntime

        testCompile( 'com.netflix.nebula:nebula-test:2.2.0' ) {
            exclude module: 'groovy-all'
        }
    }

    task integTest(type: Test) {
        testClassesDir  = sourceSets.integTest.output.classesDir
        classpath     = sourceSets.integTest.runtimeClasspath
    }

    check.dependsOn -= integTest

这是我的简单集成测试规范(我在第一次尝试之后添加了一个" def"这没有任何区别):

import nebula.test.IntegrationSpec
class YangPluginIntegSpec extends IntegrationSpec {
    def 'simple'() {
        writeHelloWorld("com.example")
    }
}

更新

这里是错误的完整堆栈跟踪。

  

groovy.lang.MissingPropertyException:没有这样的属性:类的setupMethod:org.spockframework.runtime.model.SpecInfo   可能的解决方案:setupMethods       在org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:51)       在org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:63)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)       at com.energizedwork.spock.extensions.TempDirectoryInterceptor.install(TempDirectoryExtension.groovy:92)       at com.energizedwork.spock.extensions.TempDirectoryInterceptor $ install.call(Unknown Source)       在org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)       在org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)       at com.energizedwork.spock.extensions.TempDirectoryExtension.visitFieldAnnotation(TempDirectoryExtension.groovy:21)       at com.energizedwork.spock.extensions.TempDirectoryExtension.visitFieldAnnotation(TempDirectoryExtension.groovy)       在org.spockframework.runtime.ExtensionRunner.doRunAnnotationDrivenExtensions(ExtensionRunner.java:100)       在org.spockframework.runtime.ExtensionRunner.runAnnotationDrivenExtensions(ExtensionRunner.java:65)       在org.spockframework.runtime.ExtensionRunner.runAnnotationDrivenExtensions(ExtensionRunner.java:60)       在org.spockframework.runtime.ExtensionRunner.runAnnotationDrivenExtensions(ExtensionRunner.java:51)       在org.spockframework.runtime.ExtensionRunner.run(ExtensionRunner.java:41)       在org.spockframework.runtime.Sputnik.runExtensionsIfNecessary(Sputnik.java:88)       在org.spockframework.runtime.Sputnik.getDescription(Sputnik.java:55)       at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:83)       at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)       at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:64)       在org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:50)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:606)       在org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)       在org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)       在org.gradle.messaging.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)       at org.gradle.messaging.dispatch.ProxyDispatchAdapter $ DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)       at com.sun.proxy。$ Proxy2.processTestClass(Unknown Source)       在org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:106)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:606)       在org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)       在org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)       在org.gradle.messaging.remote.internal.hub.MessageHub $ Handler.run(MessageHub.java:360)       at org.gradle.internal.concurrent.DefaultExecutorFactory $ StoppableExecutorImpl $ 1.run(DefaultExecutorFactory.java:64)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:744)

然后我尝试在调试器中单步执行此代码。我能够在AbstractCallSiteCallGetProperty()第227行触及断点。在我的测试用例中它打了几十次这个断点。我还在第63行的GetEffectivePojoPropertySite.getProperty()中设置了一个断点,但由于某种原因它从不会遇到该断点。

" callGetProperty()"方法如下所示:

public Object callGetProperty(Object receiver) throws Throwable {
    return acceptGetProperty(receiver).getProperty(receiver); // 227
}

该方法如下所示:

public final Object getProperty(Object receiver) throws Throwable {
    try {
        return effective.getProperty(receiver); // line 61
    } catch (GroovyRuntimeException gre) {
        throw ScriptBytecodeAdapter.unwrap(gre); // line 63
    }
}

由于第63行在catch子句中,我还在第61行设置了断点,并且该断点也从未被击中。

更新

另一个有趣的点是TempDirectoryInterceptor.install()方法调用了栈跟踪:

@Override
void install(SpecInfo spec) {
    spec.setupMethod.addInterceptor this // line 92
    spec.cleanupMethod.addInterceptor this
}

有" setupMethod",但我不知道那应该是什么。在此行上设置的断点不会被击中。

1 个答案:

答案 0 :(得分:0)

正如我在评论中所说,最新发布的nebula.test需要Spock 0.7。如果您还将Spock 1.0指定为依赖项,则会出现混乱。解决方法是删除对Spock 1.0的单独引用。

幸运的是,nebula.test可能会很快升级为使用Spock 1.0。以下PR请求待处理:https://github.com/nebula-plugins/nebula-test/pull/33