仍然是Grails的新手,非常喜欢学习和解决问题,但有时候看起来很简单的事情只会让我感到困惑。
Grails生成的ControllerSpec类包括一些明智的测试,其中大多数都很简单明了,但是有人可以在此测试中向我解释一些语法/逻辑:
void "Test the index action returns the correct model"() {
when:"The index action is executed"
controller.index()
then:"The model is correct"
!model.fooBarList
model.fooBarCount == 0
}
特别是以下几行:
!model.fooBarList
逻辑似乎对我来说是错误的,调用
controller.index()
将填充model.fooBarList
,那么为什么断言它不存在?我完全希望在这里能过一会儿,但我需要到达那里的帮助!
最佳答案
The logic seems wrong to me, calling controller.index() will populate model.fooBarList so why assert that it doesn't exist?
并不是说
fooBarList
不存在。 model.fooBarList
应该是一个空列表,也将通过该测试。
关于grails - Grails 3.0生成的ControllerSpec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33520977/