【发布时间】:2011-02-27 15:38:23
【问题描述】:
我正在使用 EMMA eclipse 插件来生成代码覆盖率报告。 我的应用程序是一个 RESTFul 网络服务。 编写 Junit 以便为 Web 服务创建客户端并使用各种输入调用。
但是 EMMA 显示源文件夹的覆盖率为 0%。仅测试文件夹被覆盖。
应用服务器(jetty server)使用main方法启动。
报告:
Element Coverage Covered Instructions Total Instructions
MyRestFulService 13.6% 900 11846
src 0.5% 49 10412
test 98% 1021 1434
Junit 测试方法:
@Test
public final void testAddFlow() throws Exception {
Client c = Client.create();
WebResource webResource = c.resource(BASE_URI);
// Sample files for Add
String xhtmlDocument = null;
Iterator iter = mapOfAddFiles.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry pairs = (Map.Entry) iter.next();
try {
document = helper.readFile(requestPath
+ pairs.getKey());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/* POST */
MultiPart multiPart = new MultiPart();
multiPart.bodyPart(....
...........
ClientResponse response = webResource.path("/add").type(
MEDIATYPE_MULTIPART_MIXED).post(ClientResponse.class,
multiPart);
assertEquals("TESTING ADD FOR >>>>>>> " + pairs.getKey(),
Status.OK, response.getClientResponseStatus());
}
}
}
调用的服务方法:
@POST
@Path("add")
@Consumes("multipart/mixed")
public Response add(MultiPart multiPart)
throws Exception {
Status status = null;
List<BodyPart> bodyParts = null;
bodyParts = multiPart.getBodyParts();
status = //call to business layer
return Response.ok(status).build();
}
【问题讨论】:
标签: web-services client rest code-coverage