与其他集成测试一起运行时,Spock 集成测试失败 - 使用 integration:spock 隔离成功



我正在为grails 2.1.1应用程序的现有测试集添加第一个spock集成测试。 测试运行,测试在运行时通过:

grails test-app integration:spock CreditServiceSpec

(是的,一切都在默认包中 - 修复这是大量不会被批准的工作......在技术债务下提交。

但是,当我运行所有测试(grails test-app)时,单元测试通过,spock单元测试通过,集成测试通过,但是spock集成出现以下失败:

|完成 818 次集成测试,0 次在 104001ms 内失败 |运行 1 个斯波克测试... |失败:信用服务规范 | groovy.lang.GroovyRuntimeException: failed to invoke constructor: public org.codehaus.groovy.grails.test.support.GrailsTestAutowirer(org.springframework.context.ApplicationContext) 带有参数: [] 原因: java.lang.IllegalArgumentException at grails.plugin.spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:33) |完成 0 斯波克测试,0 次在 33ms 内失败 |测试通过 - 在/Users/*/projects/GrailsPlugins/DomainServices/target/test-reports 中查看报告

无论我运行我构建的完整测试还是以下非常精简的示例,我都会得到完全相同的异常:

import grails.plugin.spock.IntegrationSpec
class CreditServiceSpec extends IntegrationSpec {
    def setup() {}
    def cleanup() {}
    public void "sample"() {
        setup:"Nothing to do here."
        expect:"This is the truest of truths..."
        true == true
    }
}

我确实打开了 IntegrationSpec 并查看了第 33 行:

@Shared private autowirer = new GrailsTestAutowirer(applicationContext)

但是,确定如何/为什么应用程序上下文没有正确传入超出了我的范围,也许是我问题的重点。

有没有人遇到过这种行为,并找到了一种方法让 spock 集成与其他测试很好地配合使用? 谢谢。

看起来Grails 2.1.1在集成范围内的Spock测试中存在几个问题。 杰夫的评论和彼得的评论听起来特别像你遇到的问题;基本上,应用程序持有人为空或空列表。

父任务将 Grails 2.2.5 列为修复版本。您是否有机会升级到该版本(甚至更高版本)并查看问题是否仍然存在?

在某些情况下,一个简单的grails clean已经解决了这样的问题。

我遇到了完全相同的症状。

我正在使用 BuildTestData 插件并在 IntegrationSpec 中使用了@Build注释,但是使用 @Build 使用转换扩展了与 Intengration 运行时不兼容的@TestFor转换。

因此,只需删除@Build注释,它就会运行。

最新更新