【发布时间】:2021-06-09 20:19:15
【问题描述】:
在示例https://guides.grails.org/grails-controller-testing/guide/index.html 中,成功案例需要有效负载,但这不应该是要求,测试应该只是验证操作实际上应该做什么?
例子:
class OneController {
def list(OneCommand command) {
if (command.hasErrors()) {
render command.errors as JSON
return
}
respond oneService.save(command.param1) as JSON
}
}
如果 command 有效,则必须调用 Stub(oneService.save()) 传递 command.param1 作为参数,返回必须是该服务的 JSON 返回。
如果命令无效,它应该以 JSON 格式返回 command.errors。
在另一个单元测试中,测试 OneCommand。
【问题讨论】:
标签: unit-testing grails controller