【发布时间】: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