我正在尝试为Grails 2.4.0中的RestfulController编写一些集成测试,以JSON格式进行响应.index() - Method实现如下:
class PersonController extends RestfulController<Person> {
...
def index(final Integer max) {
params.max = Math.min(max ?: 10, 100)
respond listAllResources(params), [includes: includeFields]
}
...
}
Run Code Online (Sandbox Code Playgroud)
集成测试如下所示:
void testListAllPersons() {
def controller = new PersonController()
new Person(name: "Person", age: 22).save(flush:true)
new Person(name: "AnotherPerson", age: 31).save(flush:true)
controller.response.format = 'json'
controller.request.method = 'GET'
controller.index()
assertEquals '{{"name":"Person", "age": "22"},{"name":"AnotherPerson", "age": "31"}}', controller.response.json
}
Run Code Online (Sandbox Code Playgroud)
我不明白的是controller.response.json只包含"AnotherPerson"而不是两个条目.当我使用run-app启动服务器并使用Rest-Client测试它时我得到两个条目.有任何想法吗?