Grails集成测试响应对象在后续调用控制器后不会更改

时间:2013-07-10 20:10:23

标签: grails groovy integration-testing

我有以下集成测试。从本质上讲,它在我们的数据库中保存了一个“帐户”对象,该对象在1:many关系中具有3个SdkApplication对象的限制。我想通过运行集成测试来测试它是否在控制器中正确实施。唯一的问题是sac.response.json的最后一行每次都返回相同的内容,即使控制器已经呈现了不同的结果。

在集成测试中是否需要在grails控制器的调用之间调用一些响应清除方法?

void testAddTooManySdkApplicationBackOfficeUserFails() {
    doTestLoginJasonBackofficeUser(sac)
    def account = ObjectMother.account("TestCo")
    account.maxAuthorized3rdPartyApps = 3
    account.company.save(flush: true)
    account.save(flush: true, failOnError: true)

    3.times {
        setJSONRequest([name: "Amazing Application", accountId: account.id], sac)
        sac.addSdkApplication()
        assertSDKAddedCorrectly(sac.response.json as JSONObject)
    }

    setJSONRequest([name: "Amazing Application", accountId: account.id], sac)
    sac.addSdkApplication()
    def resp = sac.response.json as JSONObject
    assertFalse("Should have failed to add an SDKApplication as the limit was reached", resp.success)
}

1 个答案:

答案 0 :(得分:2)

尝试调用yourController.reset()或response.reset()