【问题标题】:Grails\Groovy Syntax Sugar not being added in Webflow integration tests on command lineGrails\Groovy 语法 Sugar 未添加到命令行的 Webflow 集成测试中
【发布时间】:2014-12-11 15:30:39
【问题描述】:

我有一个测试 webflow 的集成测试,每当它到达正在测试的控制器代码中的某个点时,我都会看到类似于以下内容的错误:

org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing org.codehaus.groovy.grails.webflow.engine.builder.ClosureInvokingAction@ac0e86f in state 'blahQuestions' of flow 'blahBlah' -- action execution attributes were 'map[[empty]]'
    at grails.test.WebFlowTestCase.signalEvent(WebFlowTestCase.groovy:142)
    at com.blah1.blah2.blah3.blah4.BlahFlowIntegrationTests.testblahQuestions(BlahFlowIntegrationTests.groovy:91)
Caused by: groovy.lang.MissingPropertyException: No such property: blahMessage for class: org.springframework.webflow.core.collection.LocalAttributeMap
    at com.blah1.blah2.blah3.blah4.BlahController$_closure2_closure15_closure22.doCall(BlahController.groovy:178)

被有问题的部分抛出:flow.blahMessage = '' 其中flow.put('blahMessage', '') 可以正常工作。这只发生在我从命令行运行测试时:grails test-app integration:,测试从 eclipse 运行 RightClick on test -> Run As -> Grails Command (test-app) 工作正常。

Grails 2.2.3

为什么会发生这种情况,我该如何解决?

更新:

当我通过命令行单独运行测试时,测试将通过,但如果我运行所有集成测试,它会失败。

【问题讨论】:

  • 你写道:Sorry BalRog the typo was my bad on the question, in the actual code they match, I have to modify it per policy, I should have double checked all the spelling. 其实我也犯了一个错误。我打算发表我的“答案”作为评论。我现在把它拿下来了。
  • 您还写道:I suspect it is being treated as a fixed-property class I just don't know why since it works fine in the actual code. 似乎LocalAttributeMap 在其属性集初始化后不允许您添加新属性(映射键)。您是否有可能在一个上下文中实例化为 LocalAttributeMap 而不是另一个?
  • 至于两种不同的值设置方式,我运行测试时只有一行是不同的,测试运行之间没有其他代码更改。我使用的是setCurrentState('blahQuestions'),而不是从头开始。但是,一行代码更改了修复,因此我认为它不相关。

标签: grails integration-testing grails-controller spring-tool-suite syntactic-sugar


【解决方案1】:

看起来这是测试污染,正如我的编辑“当我通过命令行运行测试本身时测试将通过,但如果我运行所有集成测试它失败”所证明的那样。原来在其中使用 @TestFor@Mock 的其他集成测试,你应该只在单元测试中使用。

我通过遵循 Ted Naleid 的 article '修复 Grails 测试在隔离中通过但在作为套件运行时失败' 这正是发生在我身上的事情来解决这个问题强>。本文提供了一个 groovy 类,您可以使用它来查找您的测试仍会失败的最小测试组合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    • 2010-10-19
    • 1970-01-01
    • 2011-08-14
    • 2013-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多