我正在为 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) 带参数:[] 原因:grails.plugin 的 java.lang.IllegalArgumentException .spock.IntegrationSpec.$spock_initializeSharedFields(IntegrationSpec.groovy:33) | 完成 0 次 spock 测试,0 次在 33 毫秒内失败 | 测试通过 - 查看 /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 集成与其他测试配合得很好的方法?谢谢。