问题
I am trying to integrate Jacoco to get the code coverage for my Cucumber tests using Maven. Following is my project structure:
-src-main-java-Pages
-src-main-java-Helper
-src-test-java-resources-features
-src-test-java-Steps
Following is the Jacoco configuration in my POM.xml
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco.exec</dataFile>
<outputDirectory>${basedir}/target/coverage-reports/jacoco</outputDirectory>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<includes>
<include>**/*Steps.*</include>
</includes>
</rule>
<rule>
<element>PACKAGE</element>
<excludes>
<exclude>**/*Pages.*</exclude>
<exclude>**/*Page.*</exclude>
</excludes>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
I am able to generate the code coverage report. However, in the report, it covers all the classes in the -src-main packages. As per different google researches and SO posts, I tried to modify my POM to exclude Pages and include only Steps in my code coverage report. But somehow, it keeps on displaying all the files in the main package.
Am I taking the wrong approach? I just want to create a report which does code coverage for only the tests that I execute rather than all the files in the main package.
回答1:
See https://maven.apache.org/guides/mini/guide-configuring-plugins.html - you specify exclusions in configuration of
<execution>
<id>check</id>
<goals>
<goal>check</goal>
but not in configuration of
<execution>
<id>report</id>
<goals>
<goal>report</goal>
so it has effect on check
, but not on report
.
来源:https://stackoverflow.com/questions/58536904/code-coverage-for-cucumber-tests-using-jacoco