集成测试中控制器动作的响应是错误的(但模型是正确的)(Grails)

集成测试中控制器动作的响应是错误的(但模型是正确的)(Grails),grails,controller,integration-testing,Grails,Controller,Integration Testing,控制器看起来像: class HistoryController { def list() { def messages = ... some db query ... [messages: messages] } } class HistoryControllerTests extends GroovyTestCase { void testList() { // login to spring security bec

控制器看起来像:

class HistoryController {
    def list() {
        def messages = ... some db query ...
        [messages: messages]
    }
}
class HistoryControllerTests extends GroovyTestCase {
    void testList() {
        // login to spring security because list query needs user info

        // create some messages and save to the DB

        def hc = new HistoryController()
        def model = hc.list()
        def html = hc.response.contentAsString

        ...
    }
}
没什么特别的。我确实在视图目录的正确位置有一个list.gsp。如果我在浏览器中访问该网站,一切都是完美的

我的集成测试如下所示:

class HistoryController {
    def list() {
        def messages = ... some db query ...
        [messages: messages]
    }
}
class HistoryControllerTests extends GroovyTestCase {
    void testList() {
        // login to spring security because list query needs user info

        // create some messages and save to the DB

        def hc = new HistoryController()
        def model = hc.list()
        def html = hc.response.contentAsString

        ...
    }
}
模型是完全正确的,所以我们知道它正在进行正确的控制器调用。但是,html等于完全不同的controlle操作的结果,甚至不属于HistoryController!。如果在调用列表之前重置控制器响应,则响应为空字符串


发生什么事了?关于追踪这个有什么建议吗?我使用的是Grails 2.0。

HistoryController和HistoryControllerTests是否具有相同的包?是的,它们位于相同的包中。