grails: how to test controller with multiple actio

2019-08-01 04:20发布

问题:

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