grails - Grails 3.0生成的ControllerSpec

标签 grails controller specifications

仍然是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/

相关文章:

shell - Grails shell 不会重新编译更改的文件

json - 如何在Grails中更新现有JSON对象的参数?

grails - 如何在Grails上公开目录?

java - 可以在 HttpServletResponse.sendRedirect() 中发送隐藏参数吗?

controller - 从 Yii 中的 Controller 调用另一个 Controller 中的函数

vba - 为什么这段代码在粘贴时会编译,否则会失败?

ruby-on-rails - 托管网络应用程序的成本/rails ?

AngularJS DRY Controller 结构

java - 箭头(->)运算符优先级/优先级最低,或者赋值/组合赋值的优先级最低?

HTTP 规范 : Proxy-Authorization and Authorization headers