我正在使用EMMA eclipse插件来生成代码覆盖率报告。 我的应用程序是一个RESTFul webservice。 Junit的编写方式是为web服务创建一个客户端,并通过各种输入进行调用。EclEmma JAVA代码覆盖率 - 无法覆盖RESTful Web服务的服务层
但是,EMMA显示源文件夹的覆盖率为0%。仅包含测试文件夹。
应用程序服务器(jetty服务器)使用主要方法启动。
报告:
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();
}