Reputation: 4118
Thank you in advance for any help provided. I have a method, inside a controller which ends with a classical redirect, as follows:
redirect(action: 'login', params: params)
I would like to test this in my integration test.
For the action
part, I do as follows:
assert creditProviderController.response.redirectedUrl.startsWith("/creditProvider/login")
First of all, isn't there anything cleaner to avoid the startsWith()
call ?
And then, how can I test the params
part ?
I have been looking around and cannot find this answer.
I wish you a pleasant day !
Upvotes: 1
Views: 1479
Reputation: 418
assert response.redirectedUrl == '/roleClientProfile/create?user.id=1'
Upvotes: 4
Reputation: 516
I would recommend testing the controller via a unit test that extends ControllerUnitTestCase. That gives you a very clean way to test your call to redirect(). For example:
assertEquals("login", redirectArgs.action)
assertNotNull(redirectArgs.params.username)
Test as much as reasonable via unit tests (especially the flow logic in controller actions), and use integration tests just to make sure everything plays nicely together and to verify the system state.
Upvotes: 3