I have been assigned a task where I want to generate the code coverage report of web application execution (development code) when a manual or automation test script is executed, I have to identify (using any tool) what percent of development code has been executed against that particular action. After doing my RnD, I found that this can be achieved using JaCoCo (Java Code Coverage). JaCoCo uses class file instrumentation to record execution coverage data. Class files are instrumented on-the-fly using a Java agent. I have used the java command in the java agent flag.
Points to Mention
- Application front-end is Angular, backend is Java/BPM and is deployed on JBoss Server.
- Backend code contain multiple modules.
- Testcase are executed from my local machines, that hits the application deployed on the server.
APPROACH
- I have added the below mentioned command in /app/JBoss-EAP-7.2/bin/standalone.sh file because this is the file that is executed when the server starts.
Javaagent:<path_to>/jacocoagent.jar=classdumpdir=<path_to>/jacocoClassDump, destfile=<path_to>/jacocoST.exec
- Restart JBoss server. [After this jacocoST.exec file is created in the respective folder]
- Run automated testcase using maven on my local machine.
- Stop the JBoss server. [so that jacocoST.exec file is updated]
- Run the command:
java -jar <path_to>/jacococli.jar report <path_to>/jacoco-it.exec -- classfiles=<path_to>/jacocoClassDump --html /app/Jacocoreport --xml cov.xml
The above steps show error Can't add different class with same name
Why do I get the error "Can't add different class with same name"?
The FAQ that I’ve come across from JaCoCo Official Documentation
For coverage report generation all classes within a group must have unique names. You get this error during report generation if JaCoCo is supplied with multiple different class files with the same name. To fix this remove those duplicate classes or create separate reports or report groups for each version.
The main problem is the error which I am getting. According to FAQ, they suggest to delete duplicate files but there are no duplicate class files (each class files has unique number at the end).If somebody has done such work so please guide me, Are the steps which I followed right?