0

我有以下代码:

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(我已经读过它是针对空 url 问题的修复),那么我会得到No such property: params. 我需要做什么才能让这个测试生效?

4

1 回答 1

2

尝试使用controller.redirectArgs.action...

assertThat(controller.redirectArgs.action, equalTo("index"))
于 2012-05-29T19:26:33.983 回答