Tiago Pinto
Tiago Pinto

Reputation: 51

can´t get any code coverage from jacoco netbeans

I am making a university project and I need local code coverage to see if I'm getting my tests done right. However, netbeans console keeps

--- jacoco-maven-plugin:0.7.7.201606060606:report (report) @ ClientServicesProvider --- Skipping JaCoCo execution due to missing execution data file.

here is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!--
    In this file, DO NOT EDIT any of following elements
    -->
    <groupId>com.mycompany</groupId>
    <artifactId>ClientServicesProvider</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <mainClass>com.mycompany.tp3.MainApp</mainClass>
    </properties>

    <dependencies>
        <!-- Students can only add new dependencies to this section -->

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.3.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.3.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.xmlunit</groupId>
            <artifactId>xmlunit-core</artifactId>
            <version>2.6.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.xmlunit</groupId>
            <artifactId>xmlunit-matchers</artifactId>
            <version>2.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jfoenix</groupId>
            <artifactId>jfoenix</artifactId>
            <version>8.0.8</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <scope>test</scope>
            <version>2.44.0</version>
        </dependency>
        <dependency>
            <groupId>com.opera</groupId>
            <artifactId>operadriver</artifactId>
            <scope>test</scope>
            <version>1.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium-remote-driver</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <!-- Required for compiling the project usign maven -->
            <plugin><!-- Compiler configuration-->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>

                    <showWarnings>true</showWarnings>   <!-- Needs this -->



                    <!-- <encoding>${project.build.sourceEncoding}</encoding> -->

                </configuration>
            </plugin>



            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>

                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/../bin/javafxpackager</executable>
                            <arguments>
                                <argument>-createjar</argument>
                                <argument>-nocss2bin</argument>
                                <argument>-appclass</argument>
                                <argument>${mainClass}</argument>
                                <argument>-srcdir</argument>
                                <argument>${project.build.directory}/classes</argument>
                                <argument>-outdir</argument>
                                <argument>${project.build.directory}</argument>
                                <argument>-outfile</argument>
                                <argument>${project.build.finalName}.jar</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>default-cli</id>
                        <goals>
                            <goal>exec</goal>                            
                        </goals>
                        <configuration>
                            <executable>${java.home}/bin/java</executable>
                            <commandlineArgs>${runfx.args}</commandlineArgs>
                        </configuration>
                    </execution>
                </executions>  
            </plugin>

            <!-- Required for running unit tests -->
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                    <!-- new configuration needed for coverage per test -->
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>org.sonar.java.jacoco.JUnitListener</value>
                        </property>
                    </properties>

                </configuration>
                <dependencies>
                    <!-- This dependency must be included, otherwise Maven Surefire will not recognise the test cases -->
                    <dependency>
                        <groupId>org.junit.platform</groupId>
                        <artifactId>junit-platform-surefire-provider</artifactId>
                        <version>1.2.0</version>
                    </dependency>
                </dependencies>

            </plugin>

            <!-- Required for generating coverage report -->
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.7.201606060606</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


            <!-- Required for generating PIT Mutation reports -->
            <plugin>
                <groupId>org.pitest</groupId>
                <artifactId>pitest-maven</artifactId>
                <version>1.4.3</version>
                <dependencies>
                    <dependency> <!-- Only required because PITest does not work with JUnit5 without it -->
                        <groupId>org.pitest</groupId>
                        <artifactId>pitest-junit5-plugin</artifactId>
                        <version>0.8</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <!--<timestampedReports>false</timestampedReports>-->
                    <!--<inScopeClasses>
                        <param>com.mycompany.*</param>
                        <param>lapr.project.model.*</param>
                        <param>lapr.project.utils.*</param>
                    </inScopeClasses>-->
                    <targetClasses>
                        <param>com.mycompany.criagajos3000.*</param>
                        <param>com.mycompany.tp3.*</param>
                        <param>lapr.project.autorizacao.*</param>
                        <param>lapr.project.gpsd.controller.*</param>
                        <param>lapr.project.gpsd.model.*</param>

                    </targetClasses>
                    <targetTests>
                        <param>com.mycompany.criagajos3000.*</param>
                        <param>com.mycompany.tp3.*</param>
                        <param>lapr.project.autorizacao.*</param>
                        <param>lapr.project.gpsd.controller.*</param>
                        <param>lapr.project.gpsd.model.*</param>
                    </targetTests>
                    <outputFormats>
                        <outputFormat>XML</outputFormat>
                        <outputFormat>HTML</outputFormat>
                    </outputFormats>
                    <!--<verbose>true</verbose>-->
                </configuration>
            </plugin>

            <!-- Build an executable JAR -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Upvotes: 1

Views: 1975

Answers (1)

Godin
Godin

Reputation: 10574

Your pom.xml contains

                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <argLine>-Dfile.encoding=UTF-8</argLine>

However quoting JaCoCo documentation at http://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html:

If your project already defines VM arguments for test execution, be sure that they will include property defined by JaCoCo.

One of the ways to do this in case of maven-surefire-plugin - is to use syntax for late property evaluation:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>@{argLine} -your -extra -arguments</argLine>
  </configuration>
</plugin>

Another way is to define "argLine" as a Maven property rather than as part of the configuration of maven-surefire-plugin:

<properties>
  <argLine>-your -extra -arguments</argLine>
</properties>
...
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <!-- no argLine here -->
  </configuration>
</plugin>

So define argLine as property:

    <build>
      <properties>
        <argLine>-Dfile.encoding=UTF-8</argLine>
      </properties>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.1</version>
        <configuration>
          <!-- no argLine here -->

Unrelated to your problem, however I would also recommend to use most recent JaCoCo version, which is 0.8.4 as of today instead of 3 years old version 0.7.7.

Upvotes: 2

Related Questions