Grails集成测试响应对象在后续调用控制器后不会更改
我有下面的集成测试。实际上,它在数据库中保存了一个“account”对象,该对象在1:many关系中限制为3个SdkApplication对象。我想通过运行集成测试来测试这是否在控制器中正确实施。唯一的问题是sac.response.json的最后一行每次都返回相同的内容,即使控制器呈现了不同的结果 在集成测试中,在调用grails控制器之间是否需要调用一些响应明确的方法Grails集成测试响应对象在后续调用控制器后不会更改,grails,groovy,integration-testing,Grails,Groovy,Integration Testing,我有下面的集成测试。实际上,它在数据库中保存了一个“account”对象,该对象在1:many关系中限制为3个SdkApplication对象。我想通过运行集成测试来测试这是否在控制器中正确实施。唯一的问题是sac.response.json的最后一行每次都返回相同的内容,即使控制器呈现了不同的结果 在集成测试中,在调用grails控制器之间是否需要调用一些响应明确的方法 void testAddTooManySdkApplicationBackOfficeUserFails() { d
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)
}
尝试调用controller.reset()或response.reset()
controller.reset()
对我来说导致了groovy.lang.MissingMethodException
错误,但response.reset()
效果很好。