Adding jacoco coverage reporting

This commit is contained in:
2022-07-07 08:23:54 -05:00
parent eb38e0c0a5
commit 58157ff310

65
pom.xml
View File

@ -44,6 +44,8 @@
<maven.compiler.target>17</maven.compiler.target> <maven.compiler.target>17</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation> <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<maven.compiler.showWarnings>true</maven.compiler.showWarnings> <maven.compiler.showWarnings>true</maven.compiler.showWarnings>
<coverage.haltOnFailure>true</coverage.haltOnFailure>
<coverage.instructionCoveredRatioMinimum>0.80</coverage.instructionCoveredRatioMinimum>
</properties> </properties>
<dependencies> <dependencies>
@ -121,6 +123,10 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version> <version>3.0.0-M5</version>
<configuration>
<!-- Sets the VM argument line used when integration tests are run. -->
<argLine>@{jaCoCoArgLine}</argLine>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -174,23 +180,38 @@
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version> <version>0.8.8</version>
<configuration>
<excludes>
<exclude>com/kingsrook/qqq/backend/core/model/**/*.class</exclude>
<exclude>com/kingsrook/qqq/backend/core/exceptions/**/*.class</exclude>
</excludes>
</configuration>
<executions> <executions>
<execution> <execution>
<id>jacoco-check</id> <id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jaCoCoArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>unit-test-check</id>
<goals> <goals>
<goal>check</goal> <goal>check</goal>
</goals> </goals>
<configuration> <configuration>
<!-- Gives us the ability to pass a parameter to not fail due to coverage E.g. -Dcoverage.haltOnFailure=false -->
<haltOnFailure>${coverage.haltOnFailure}</haltOnFailure>
<rules> <rules>
<rule> <rule>
<!-- <element>PACKAGE</element> -->
<element>BUNDLE</element> <element>BUNDLE</element>
<limits> <limits>
<limit> <limit>
<!-- <counter>LINE</counter> -->
<counter>INSTRUCTION</counter> <counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value> <value>COVEREDRATIO</value>
<minimum>0.80</minimum> <minimum>${coverage.instructionCoveredRatioMinimum}</minimum>
</limit> </limit>
</limits> </limits>
</rule> </rule>
@ -198,13 +219,43 @@
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>report</id> <id>post-unit-test</id>
<phase>prepare-package</phase> <phase>verify</phase>
<goals> <goals>
<goal>report</goal> <goal>report</goal>
</goals> </goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>3.0.0</version>
<executions>
<execution>
<id>test-coverage-summary</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration> <configuration>
<outputDirectory>${project.build.directory}/jacoco</outputDirectory> <executable>sh</executable>
<arguments>
<argument>-c</argument>
<argument>
<![CDATA[
echo "Element\nInstructions Missed\nInstruction Coverage\nBranches Missed\nBranch Coverage\nComplexity Missed\nComplexity Hit\nLines Missed\nLines Hit\nMethods Missed\nMethods Hit\nClasses Missed\nClasses Hit\n" > /tmp/$$.headers
xpath -q -e '/html/body/table/tfoot/tr[1]/td/text()' target/site/jacoco/index.html > /tmp/$$.values
echo
echo "Jacoco coverage summary report:"
echo " See also target/site/jacoco/index.html"
echo " and https://www.jacoco.org/jacoco/trunk/doc/counters.html"
echo "------------------------------------------------------------"
paste /tmp/$$.headers /tmp/$$.values | tail +2 | awk -v FS='\t' '{printf("%-20s %s\n",$1,$2)}'
rm /tmp/$$.headers /tmp/$$.values
]]>
</argument>
</arguments>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>