我正在使用grails plugin multi-tenant-single-db。在這種情況下,我需要編寫一個spock測試,我們暫時刪除租戶限制。位置是我的房客,所以我的方法是這樣的:Spock當測試方法包含關閉時測試
def loadOjectDetails(){
Location.withoutTenantRestriction{
// code here to retrieve specific items to the object to be loaded
render(template: "_loadDetails", model:[ ... ]
}
}
的方法運行正常,但試圖把方法下的測試覆蓋率的錯誤輸出提示:
groovy.lang.MissingMethodException: No signature of method: com.myPackage.myController.Location.withoutTenantRestriction() is applicable for argument types:
和堆棧跟蹤該源於此。
我需要存根嗎? withoutTenantRestriction是我整個方法邏輯的一個包裝。
UPDATE: 測試代碼如下所示:
given:
params.id = 3002
currentUser = Mock(User)
criteriaSetup()
controller.getSalesOrder >> salesOrders[2]
when:
controller.loadOrderManageDetails()
then:
(1.._) controller.springSecurityService.getCurrentUser() >> currentUser
expect:
view == 'orderMange/orderManageDetail'
model.orderInstance == salesOrders[2]
測試代碼是什麼樣的? – railsdog
我按照要求用我的測試代碼更新了這個問題 – TroyB