测试REST端点时的最佳方法

时间:2017-03-03 11:16:58

标签: java rest testing

我正在查看以下测试REST端点的代码:

Response response = server.newRequest("/myresource").request().buildPost(Entity.text("42")).invoke();
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
MyModel myModel = response.readEntity(MyModel.class);
assertEquals(42, myModel.getResult());

如下所述:

https://dzone.com/articles/how-test-rest-api-junit

我想知道最好将响应转换为MyModel对象并对此对象应用测试。我更倾向于这样做:

JSONObject expectedResponse = new JSONObject();
expectedResponse.put("name", "mkyong.com");
expectedResponse.put("age", new Integer(100));

assert(response, expectedResponse);

哪种方法最好?

0 个答案:

没有答案
相关问题