Gradle 抱怨初始集成测试结构缺少"setupMethod"



我正在编写我的第一个Gradle插件。默认构建运行良好,包括少量的单元测试。我现在正试图使用nebula.test.建立一个集成测试基础设施

我创建了一个空的集成测试类,以及build.gradle中的设置,以配置"integrTest"任务以及相关的源集和依赖项。我使用了网络上的几个例子和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)网址:com.energizedwork.spock.extensions.TempDirectoryInterceptor.install(TempDirectoryExtension.groovy:92)网址:com.energizedwork.spock.extensions.TempDirectoryInterceptor$install.call(未知来源)位于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)网址:com.energizedwork.spock.extensions.TempDirectoryExtension.visitFieldAnnotation(TempDirectoryExtension.groovy:21)网址:com.energizedwork.spock.extensions.TempDirectoryExtension.visitFieldAnnotation(TempDirectoryExtension.groovy)位于org.spockframework.runtime.ExtensionRunner.doRunAnnotationDriverExtensions(ExtensionRunner.java:100)位于org.spockframework.runtime.ExtensionRunner.runAnnotationDriverExtensions(ExtensionRunner.java:65)位于org.spockframework.runtime.ExtensionRunner.runAnnotationDriverExtensions(ExtensionRunner.java:60)位于org.spockframework.runtime.ExtensionRunner.runAnnotationDriverExtensions(ExtensionRunner.java:51)位于org.spockframework.runtime.ExtensionRunner.run(ExtensionRunner.java:41)网址:org.spockframework.runtime.Sutnik.runExtensionIfNenecessary(Sputnik.java:88)网址:org.spockframework.runtime.Sutnik.getDescription(Sputnik.java:55)网址:org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:83)网址:org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:49)网址:org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.productTestClass(JUnitTestClassProcessor.java:64)网址:org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.productTestClass(SuiteTestClassProcessor.java:50)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)位于java.lang.reflect.Method.ioke(Method.java:606)网址:org.gradle.messageing.dispatch.ReflectionDispatch.dispatch(ReflectionDisptch.java:35)网址:org.gradle.messageing.dispatch.ReflectionDispatch.dispatch(ReflectionDisptch.java:24)位于org.gradle.messageing.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)位于org.gradle.messageing.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)网址:com.sun.proxy.$Proxy2.processTestClass(未知来源)网址:org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:106)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)位于java.lang.reflect.Method.ioke(Method.java:606)网址:org.gradle.messageing.dispatch.ReflectionDispatch.dispatch(ReflectionDisptch.java:35)网址:org.gradle.messageing.dispatch.ReflectionDispatch.dispatch(ReflectionDisptch.java:24)位于org.gradle.messageing.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:360)在org.gradle.internal.concurrent.DefaultExecutiorFactory$StoppableExecutiorImpl$1.run(DefaultExecutiorFactory.java:64)位于java.util.concurrent.ThreadPoolExecutiator.runWorker(ThreadPoolExecutiator.java:1145)位于java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)在java.lang.Thread.run(Thread.java:744)

然后我尝试在调试器中逐步执行此代码。我能够在AbstractCallSite.callGetProperty()的第227行找到断点。在我的测试用例中,它多次碰到这个断点。我还在GetEffectivePojoPropertySite.getProperty()的第63行设置了一个断点,但由于某种原因,它从未达到该断点。

"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()方法调用stacktrace:

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

这里有"setupMethod",但我不知道应该是什么。在这行设置的断点不会被命中。

正如我在评论中所说,最新版本的nebula.test需要Spock 0.7。如果您还指定Spock 1.0作为依赖项,那么混乱将随之而来。修复方法是删除对Spock 1.0的单独引用。

幸运的是,nebula.test很可能很快就会升级为使用Spock1.0。以下PR请求处于挂起状态:https://github.com/nebula-plugins/nebula-test/pull/33。

最新更新