testing - grails:如何使用多个操作和多个重定向来测试 Controller ?

标签 testing grails redirect controller action

我遇到了以下问题: 我想测试我的 Controller 的注销操作。在此之前,我正在调用我的 Controller 的登录方法,它们都重定向到同一页面。现在我收到以下错误消息:

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())都不起作用。

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

有什么建议吗? 谢谢 多米尼克

最佳答案

好的,我找到了答案:

  1. 我忘了从父类(super class)调用 setUp:

    @Before
    void setUp() {
        super.setUp()
    
  2. 如果您想保留 session ,则不能调用 reset(),因为它也会清除您的 session 。改为调用:

    redirectArgs.clear()
    

干杯, 多米尼克

关于testing - grails:如何使用多个操作和多个重定向来测试 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8862622/

相关文章:

javascript - 使用 React 和 Enzyme 测试设置文本值

grails - 使用grails-spring-security-rest进行基于HTTP基本身份验证 token 的操作

testing - 要测试多少 Grails GORM?

Magento 添加到购物车并重定向到结账(产品页面 : on "Checkout" button, "Add to Cart"重定向到购物车)

ASP.Net Response.Redirect 在 Application_Error 中不起作用?

ios - 如何在 iOS 应用程序中自动化测试

python - 如何在不清除数据库的情况下测试 Django on_commit Hook ?

testing - Cypress 测试因我的应用程序未捕获的异常而失败 - support/index.js 不起作用

grails - 在 Geb 中,displayed 和 present 有什么区别?

php - Yii2:如何使用 POST 方法重定向?