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

时间:2013-10-29 13:38:58

标签: grails integration-testing spock

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

grails test-app integration:spock CreditServiceSpec

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

然而,当我运行所有测试(grails test-app),单元测试通过,spock单元测试通过,集成测试通过,但我得到以下spock集成失败:

  

|完成818次集成测试,0次失败,发生在104001ms   |运行1个spock测试...   |失败:CreditServiceSpec   | groovy.lang.GroovyRuntimeException:无法调用构造函数:public org.codehaus.groovy.grails.test.support.GrailsTestAutowirer(org.springframework.context.ApplicationContext),带参数:[] reason:java.lang.IllegalArgumentException       at grails.plugin.spock.IntegrationSpec。$ spock_initializeSharedFields(IntegrationSpec.groovy:33)   |完成0 spock测试,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)

但是确定applicationContext没有被正确传递的方式/原因超出了我的范围,也许是我问题的主旨。

有没有人遇到过这种行为,并找到了一种方法来使spock集成与其他测试一起玩得很好?感谢。

2 个答案:

答案 0 :(得分:1)

看起来Grails 2.1.1在Integration范围内有Spock测试several issuesJeff's commentPeter's听起来特别像您遇到的问题;基本上ApplicationHolder为null或空列表。

父任务将Grails 2.2.5列为修订版本。你有没有机会升级到那个(或者甚至更晚的版本),看看问题是否仍然存在?

还有一些简单的grails clean has fixed issues like this

答案 1 :(得分:1)

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

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

所以只需删除@Build注释即可运行。

相关问题