grails: how to test controller with multiple actions and multiple redirects?

故事扮演 提交于 2019-12-24 10:24:25

问题


i am having the following problem: i want to test the logout action of my controller. before that i am calling the login method of my controller which both redirect to the same page. now I am getting the following error message:

groovy.grails.web.servlet.mvc.exceptions.CannotRedirectException: Cannot issue a redirect(..) here. A previous call to redirect(..) has already redirected the response.

i do understand the problem, however all suggested solutions (calling the reset() method; calling GrailsWebUtil.bindMockWebRequest()) do not work.

i am doing integration testing and using the class ControllerUnitTestCase.

any suggestions? thanks dominik


回答1:


OK, I found the answer(s):

  1. I forgot to call the setUp from the super class:

    @Before
    void setUp() {
        super.setUp()
    
  2. You cannot call reset() if you want to keep your session because it also clears your session. Call instead:

    redirectArgs.clear()
    

Cheers, Dominik



来源:https://stackoverflow.com/questions/8862622/grails-how-to-test-controller-with-multiple-actions-and-multiple-redirects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!