Grails - 在集成测试中使用参数重定向()
预先感谢您提供的任何帮助。 我有一个方法,在控制器内部以经典重定向结束,如下所示:
redirect(action: 'login', params: params)
我想在我的集成测试中测试它。 对于 action
部分,我执行以下操作:
assert creditProviderController.response.redirectedUrl.startsWith("/creditProvider/login")
首先,是否有更干净的方法可以避免 startsWith()
调用? 然后,我如何测试 params
部分?
我一直在环顾四周,找不到这个答案。
祝您度过愉快的一天!
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 !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议通过扩展 ControllerUnitTestCase 的单元测试来测试控制器。这为您提供了一种非常干净的方法来测试对redirect() 的调用。例如:
通过单元测试(尤其是控制器操作中的流程逻辑)进行尽可能合理的测试,并使用集成测试来确保一切正常运行并验证系统状态。
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:
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.