我正在使用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();
}