【发布时间】:2018-09-26 15:22:47
【问题描述】:
测试 JSON 响应的首选方法是什么,尤其是要存在的属性和值?从IntegrationSpec、ControllerSpec、AppIntegrationSpec 扩展控制器的正确类型是什么?我没有在相应的Testing section 中找到正确的响应。谢谢。
【问题讨论】:
标签: activeweb
测试 JSON 响应的首选方法是什么,尤其是要存在的属性和值?从IntegrationSpec、ControllerSpec、AppIntegrationSpec 扩展控制器的正确类型是什么?我没有在相应的Testing section 中找到正确的响应。谢谢。
【问题讨论】:
标签: activeweb
在这个示例项目中有一个很好的例子: https://github.com/javalite/activeweb-rest/blob/27687e26f5476734b867d01f38b2575c6de3f3c9/src/test/java/app/controllers/PeopleControllerSpec.java#L57
public void shouldCreateNewPeopleWithAddresses(){
String json = Util.readResource("/people.json");
request().content(json.getBytes()).contentType("application/json").post("create"); // <--- need to call "create" according to REST routing
Map response = JsonHelper.toMap(responseContent());
the(response.get("code")).shouldBeEqual(200);
the(response.get("message")).shouldBeEqual("successfully created people and addresses");
}
基本上,你得到一个responseContent() 作为字符串,然后你可以用它做任何你想做的事情。规范的超类是无关紧要的。
【讨论】:
...the super class for the spec is irrelevant 下的意思是什么?