[英]ActiveWeb: testing JSON response attributes and values
测试JSON响应(尤其是其中包含的属性和值)的首选方法是什么? 什么样的控制器才是正确的类型: IntegrationSpec
, ControllerSpec
, AppIntegrationSpec
? 在相应的“ 测试”部分中找不到正确的响应。 谢谢。
如果在此示例项目中有一个很好的示例: 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");
}
基本上,您会获得一个String的responseContent()
,然后您可以使用它进行任何操作。 规格的超类无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.