Grails: redirect testing with integration test

I am using Grails 1.3.7. I am trying to check redirection in my integration test. Here is my controller and the method in question ...

class HomeController {

def design = {
    ....
            if (params.page) {
                redirect(uri: "/#/design/${params.page}")
            }
            else {
                redirect(uri: "/#/design")
            }
            break;
    }
}

However, in my integration test, the call to "controller.response.redirectedUrl" fails (always returns null), although I know that the redirect call is being made (checked by logging). What is wrong with the integration test below?

class HomeControllerTests extends grails.test.ControllerUnitTestCase {
    ....

    void testHomePageDesign() { 
       def controller = new HomeController()

       // Call action without any parameters
       controller.design()

       assert controller.response.redirectedUrl != null

       assertTrue( responseStr != "" )
    }   

Thanks - Dave

+5
source share
1 answer

Changing HomeControllerTests for the GrailsUnitTestCase extension should fix the problem.

class HomeControllerTests extends grails.test.GrailsUnitTestCase {
    ....
}

, , .

create-integration-test => GroovyTestCase
create-unit-test => GrailsUnitTestCase
create-controller => ControllerUnitTestCase

Grails GrailsUnitTestCase , , 1.3.7, .

+2

All Articles