我有以下代码:
void testConfirmBookNotFound() {
def book = new Book(id: 1, title: 'test book')
mockDomain(Book, [book])
mockDomain(BookProject, [new BookProject(id: 1, book: book)])
def controller = new CancelController()
controller.params.id = 5140
controller.confirm()
assertEquals "/admin/cancel/index", controller.response.redirectedUrl
}
如果我的测试类延伸ControllerUnitTestCase
,则controller.response.redirectedUrl
始终为null
。但是,如果我的测试类扩展GrailsUnitTestCase
(我已经阅读过这是针对null url问题的修复),那么我得到No such property: params
。我需要做些什么来使这个测试起作用?
答案 0 :(得分:2)
尝试使用controller.redirectArgs.action
,如...
assertThat(controller.redirectArgs.action, equalTo("index"))