Grails IntegrationSpec和对控制器的多次调用

Grails IntegrationSpec和对控制器的多次调用,grails,integration-testing,spock,Grails,Integration Testing,Spock,我有一个测试,我需要使用Grail的IntegrationSpec进行几个背对背的调用来测试控制器 when: "User starts a flow" controller.userSessionService.user = user controller.request.method = "POST" controller.request.contentType = "text/json" controller.request.content = ([

我有一个测试,我需要使用Grail的IntegrationSpec进行几个背对背的调用来测试控制器

    when: "User starts a flow"
    controller.userSessionService.user = user
    controller.request.method = "POST"
    controller.request.contentType = "text/json"
    controller.request.content = ([lId: l.id] as JSON).toString().getBytes()

    controller.start()

    then:
    ...

    when: "User does next step"
    controller.userSEssionService.user = user
    controller.request.method = "POST"
    controller.request.contentType = "text/json"
    controller.request.content = ([data1: data] as JSON).toString().getBytes()

    controller.nextStep()

    then:
    ...
等等等等。问题是试图更改第二次呼叫的请求内容,但它无法工作。它似乎只保留对request.content的第一个调用。我知道在以前的版本中,GroovyTestCase上有helper方法,但是由于我使用的是spec,所以没有任何方法可以调用来重置控制器的请求/响应。我尝试在每个when:节之前使用给定的重新实例化控制器。但是测试失败了

我必须按照这个顺序进行这些调用,并测试每个调用之间的状态变化。我不能在几个方法调用中分解这些。我不确定这在本例中是否重要,但我正在使用MongoDB


在使用Spock IntegrationSpec时,如何对控制器进行多次调用,并在每次调用之间重置请求/响应?

因此,我想既然Grails希望每个请求/响应周期都有一个控制器实例,那么如果执行多次请求/响应,则需要多次实例化控制器。然而,因为Grails有太多的“魔法”发生,所以你不能轻易做到这一点。如果我是实例化的话,那就容易多了。或者,如果魔术是更好地记录同样的事情。你试过写功能测试吗?这对于控制器端到端测试比集成测试更有效