WebApp Code-Coverage
In this section, we will show you the required steps to verify which backend code is being called by the front-end during the manual or automated testing.
| This tutorial is applied to Java Web Applications deployed on Tomcat, however, it could be also applied to any Java based application deployed as Standalone or as a Docker container. |
Steps
-
Create “test” folder inside your Apache-tomcat home, and as shown below, place the following jars inside it:
-
jacocoagent.jar
-
jacocoant.jar
-
jacococli.jar
-
-
In the “test” folder, create “to-html.bat” file that, which contains the following script:
java -jar jacococli.jar report test.exec --classfiles ../webapps/app/WEB-INF/classes --html html -
In Apache-tomcat home “bin” folder, create setenv.bat with the following contents:
SET CATALINA_OPTS=-javaagent:../test/jacocoagent.jar=destfile=../test.sexec,includes=com.app.*,append=false -
Start the tomcat with startup.bat script inside the bin folder.
-
Deploy your app on tomcat by placing the war file inside the webapps folder(app.war for example).
-
Run the tests on your app either manually or automatically using something like Selenium.
-
When done, shutdown the tomcat using bin/shutdown.bat batch inside tomcat.
-
Inside tomcat/test double click on to-html.bat file, then an html folder will be created.
-
Run index.html and you will be able to see the something like the following results: