我使用的是Grails 2.3.8,最近我开始修复一些过时的测试,这些测试在过去的几个Grails 2.3.x版本中停止工作。Grails控制器单元测试通过命令行而不是Intellij
在进行Spock控制器测试期间,以及在使用来自Controller的域实例进行响应时,根据测试执行环境,对模型的断言失败/通过。特别是,在使用Grails控制台vs IntelliJ(Junit)执行测试时,模型上的域实例具有不同的属性名称。
我一直在对冲它在我的斯波克的规格使得这类说法在我然后或预计块:
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
}
请投票的人请解释原因吗?不要试图争论,但我想知道我的帖子中是否有错误或缺失,可能有助于他人理解和回应。 – ZDJ
我会仔细检查你是否在这两种环境中使用相同的grails版本。很容易导致不匹配。 – allTwentyQuestions
我希望这是件小事,但我有一种感觉,它与在Intellij中配置Grails环境的方式有关。我们的生产环境中一切运行良好。一旦我在下一个Sprint中获得一些时间,我将尝试解决问题的根源。 – ZDJ