[Vuejs]-Analyze Coverage of Web Applications in Tomcat

0👍

Doing this using JaCoCo requires two steps:

1) Add jacocoagent to your Apache Tomcat, that gathers coverage data and listens on a TCP port for requests to dump those data.

In apache-tomcat/bin/setenv.bat add Javaoptions:

set JAVA_OPTS=-javaagent:c:\\path\\to\\jacoco\\lib\\jacocoagent.jar=includes=your.classes.packages.*,classdumpdir=jacocoClasses,output=tcpserver 

2) If you execute your tests using Maven, you can use the jacoco-maven-plugin for connecting to the TCP port opened by jacocoagent gathering the coverage data from your Apache Tomcat.

Incomplete example:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>default-prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
            <configuration>
                <includes>
                    <include>your/classes/packages/**</include>
                </includes>
            </configuration>
        </execution>
        <execution>
            <id>default-dump-report</id>
            <phase>test</phase>
            <goals>
                <goal>dump</goal>
            </goals>
            <configuration>
                <address>localhost</address>
                <reset>true</reset>
                <destFile>${project.build.directory}/jacoco.exec</destFile>
            </configuration>
        </execution>
        <execution>
            <id>default-report</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <includes>
                    <include>your/classes/packages/**</include>
                </includes>
            </configuration>
        </execution>
    </executions>
</plugin>

Beware that coverage data by JaCoCo are only applicable to exact thos .class files they have been collected with (identified by a check sum). Two compilations of a single .java file may result in .class files with different check sums. JaCoCo reports will thus declare it uncovered.

Leave a comment