EclEmma JAVA Code coverage - Unable to coverage service layer of RESTful Webservice
- by Radhika
I am using EMMA eclipse plugin to generate code coverage reports.
My application is a RESTFul webservice.
Junits are written such that a client is created for the webservice and invoked with various inputs.
However EMMA shows 0% coverage for the source folder. The test folder alone is covered.
The application server(jetty server) is started using a main method.
Report:
Element Coverage Covered Instructions Total Instructions
MyRestFulService 13.6% 900 11846
src 0.5% 49 10412
test 98% 1021 1434
Junit Test method:
@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());
}
}
}
Invoked service method:
@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();
}