0

我刚刚将现有应用程序从 Grails 2.2.4 升级到 2.3.0。从那时起,所有 spock 集成测试都被破坏了。我收到的错误消息如下所示。运行单元测试或运行应用程序没有问题。提前感谢您的任何建议。

| Error Fatal error running tests: No WebApplicationContext found: no ContextLoaderListener registered? (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
    at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:90)
    at grails.util.Holders.getApplicationContext(Holders.java:78)
    at _GrailsTest_groovy$_run_closure1.doCall(_GrailsTest_groovy:95)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
    at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
    at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
    at TestApp$_run_closure1.doCall(TestApp.groovy:32)
    at org.codehaus.gant.GantMetaClass.invokeMethod(GantMetaClass.java:133)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy:185)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16_closure18.doCall(GantBinding.groovy)
    at org.codehaus.gant.GantBinding.withTargetEvent(GantBinding.groovy:90)
    at org.codehaus.gant.GantBinding.this$4$withTargetEvent(GantBinding.groovy)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy:185)
    at org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure16.doCall(GantBinding.groovy)
    at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:427)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:415)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.executeTargets(Gant.groovy:591)
    at gant.Gant.executeTargets(Gant.groovy:590)
| Error Fatal error running tests: No WebApplicationContext found: no ContextLoaderListener registered?
4

2 回答 2

0

对于 grails >= 2.3,您不再需要将 Spock 插件添加到您的项目中。

像以前一样简单地创建 Spock 规范,它们将作为单元测试运行。事实上,不要安装 Spock 插件,否则您的规范将运行两次并可能失败。这也意味着 spock 测试类型不再存在。

规范和 JUnit 测试现在以相同的类型运行。

于 2013-10-29T14:57:54.563 回答
0

好的。我前一阵子想通了。

原因是我试图在集成测试中模拟 servletcontext,而 Grails 2.3.2 已经提供了它。删除模拟的 servletContext 后,一切正常。

于 2013-11-26T02:22:38.357 回答