【发布时间】:2014-07-02 17:37:51
【问题描述】:
我正在使用 Grails 2.3.8,最近我开始修复一些过时的测试,这些测试在过去的几个 Grails 2.3.x 版本中停止工作。
在 Spock 控制器测试期间,以及从控制器响应域实例时,针对模型的断言失败/通过取决于测试执行环境。具体来说,当使用 Grails 控制台与 IntelliJ (Junit) 执行测试时,模型上的域实例具有不同的属性名称。
我一直在通过在我的 Spock 规范中的 then 或 expect 块中做出这种类型的断言来对冲它:
void "show action correctly handles a valid instance"() {
given: "a valid domain instance"
def myDomainObject = MyDomainClass.build()
when: "calling the show action with a valid domain instance"
controller.show(myDomainObject)
then: "respond to the show view with the domain instance set on the model"
view == ‘show’
// the property name ends with ‘Instance’ in one env and not in the other
model.myDomainObjectInstance ?: model.myDomainObject == myDomainObject
}
【问题讨论】:
-
投反对票的人能解释一下原因吗?不想争论,但我想知道我的帖子中是否有任何错误或遗漏,可能有助于其他人理解和回应。
-
我会仔细检查您在两种环境中使用的 grails 版本是否相同。很容易以不匹配而告终。
-
我希望它像那样微不足道,但我感觉它与 Intellij 中 Grails 环境的配置方式有关。在我们的生产环境中一切运行良好。一旦我在下一个 Sprint 中获得一些时间,我将尝试找到问题的根源。
-
有这方面的消息吗?我遇到了完全相同的问题。我也不想破解我的测试代码来完成这项工作。出于这个原因,我一直在通过 Intellij 中的命令行界面运行测试。
标签: grails groovy junit intellij-idea spock