grails:如何测试控制器与多个操作和多重定向? [英] grails: how to test controller with multiple actions and multiple redirects?

查看:381
本文介绍了grails:如何测试控制器与多个操作和多重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:
我想测试我的控制器的注销操作。之前,我调用我的控制器的登录方法,它们都重定向到同一个页面。现在我得到以下错误消息:

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.



我理解问题,但是所有建议的解决方案(调用reset()方法;调用GrailsWebUtil。 bindMockWebRequest())不起作用。

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

我正在进行集成测试并使用ControllerUnitTestCase类。

i am doing integration testing and using the class ControllerUnitTestCase.

建议?
感谢
dominik

any suggestions? thanks dominik

推荐答案

好的,我找到了答案:


  1. 我忘记从超级类调用setUp:

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

@Before
void setUp() {
    super.setUp()


  • 如果您想保留会话,因为它也清除了会话,您不能调用reset()。调用:

  • You cannot call reset() if you want to keep your session because it also clears your session. Call instead:

    redirectArgs.clear()
    


  • 干杯,
    Dominik

    Cheers, Dominik

    这篇关于grails:如何测试控制器与多个操作和多重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆