0
是否可以創建PagedResultList實例或模擬?Grails中的PagedResultList實例3.1.7單元測試
對於背景:目前我正在編寫控制器單元測試。如果有必要,我會保存服務功能調用。但是其中一些功能有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"
}
有人可以幫我一個PICE更換?????
的代碼來解決這個問題?
在此先感謝。
感謝這個偉大的例子。 –
@ se-jaeger是否回答了您的問題? –
是的,謝謝你的提示。 –