3

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.

automaticien
  • 153
  • 5
  • 14

1 Answers1

0

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.

Godin
  • 9,801
  • 2
  • 39
  • 76
  • I tried including and tags as well in the report configuration section. Did not work! – automaticien Oct 25 '19 at 10:07
  • 1
    Then please read https://stackoverflow.com/help/minimal-reproducible-example and provide absolutely complete example, because just snippet of `pom.xml` is not enough to reproduce you difficulty – Godin Oct 25 '19 at 11:10
  • And here is another hint for you - https://stackoverflow.com/questions/54055625/how-to-specify-the-specific-packages-for-the-jacoco-check/54058168#54058168 – Godin Oct 25 '19 at 11:29
  • I provided the details in my question based on other SO posts that I read. Plus, due to confidentiality issues at work, I can't put any other details. Anyways, the hint that you provided, I have already tried but did not work either. Thanks anyways – automaticien Oct 25 '19 at 13:16
  • "I provided the details in my question based on other SO posts that I read." that's exactly the point - if your details are not different from other questions, then these details are not enough to diagnose problem and provide solution – Godin Oct 25 '19 at 14:34