【问题标题】:PagedResultList Instance in Grails 3.1.7 Unit TestGrails 3.1.7 单元测试中的 PagedResultList 实例
【发布时间】:2016-11-08 14:17:27
【问题描述】:

是否可以创建 PagedResultList 实例或 Mock?

对于背景:目前我正在编写控制器单元测试。如果有必要,我会存根服务函数调用。但是其中一些函数将PagedResultList 作为返回类型。所以我必须注入一个PagedResultList 实例或null

在某些情况下,我需要一个实例,因为控制器会执行以下操作:

testFunction(){
    def result = sampleService.doSomething()

    if (result.empty) {
        variable = "it´s empty"
    }
    render variable
}

我的测试如下所示:

void "sample Test"(){
    given:
        controller.sampleService = Mock(SampleService)
        PagedResultList emptyPagedResultList = ?????

    when:
        controller.testFunction()

    then:
        1 * controller.sampleService.doSomething() >> emptyPagedResultList
        response.text == "it´s empty"
}

有人可以帮我用一段代码替换????? 来解决这个问题吗?

提前致谢。

【问题讨论】:

    标签: unit-testing grails grails-3.0 grails-3.1


    【解决方案1】:

    是的,这里有几个选项:

    【讨论】:

    • 感谢这些优秀的例子。
    • @se-jaeger 回答了你的问题吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多