user1107888 user1107888 - 1 month ago 18
Java Question

JaCoCo missing executable issue

I have a small Maven application which uses JaCoCo for test coverage report. I keep getting the following error:


Skipping JaCoCo execution due to missing execution data file


Here is my POM.xml file. I have removed the Project Element myself.

<modelVersion>4.0.0</modelVersion>

<groupId>de.mathema.www</groupId>
<artifactId>jacoco_sample_app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>jacoco_sample_app</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.6.201602180812</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>
</plugins>
</build>


Here is my main class which is under the
src/main/java
structure:

public class Punkt {
private Double x;
private Double y;

public Punkt(Double x,Double y) {
this.x = x;
this.y = y;
}

public Punkt(Punkt zweiterPunkt) {
this.x = zweiterPunkt.x;
this.y = zweiterPunkt.y;
}

public Double getX() {
return x;
}

public void setX(Double x) {
this.x = x;
}

public Double getY() {
return y;
}

public void setY(Double y) {
this.y = y;
}

public boolean punkteVergleichen(Punkt zweiterPunkt) {
return this.getX().equals(zweiterPunkt.getX()) &&
this.getY().equals(zweiterPunkt.getY());

}
public String toString() {
return "("+this.x+","+this.y+")";
}

}


And here is class with unit tests which is under the
src/test/java
structure:

public class PunktUnitTests {

@Test
public void PunkteVergleichen() throws Exception {
//a(10.0, 20.0)
Punkt a = new Punkt(10.0,20.0);

//b(30.0,40.0)
Punkt b = new Punkt(30.0,40.0);

//Der Fall X1!=X2 und Y1!=Y2
//a(10.0,20.0) und b(30.0,40.0) sind unterschiedlich
assertFalse(a.punkteVergleichen(b));

//Der Fall X1 == X2 && Y1 == Y2
//a(10.0,20.0) und c(10.0,20.0) sind gleich
Punkt c = new Punkt(a);
assertTrue(a.punkteVergleichen(a));

//Der Fall X1 == X2 && Y1 != Y2
//a(10.0,20.0) und c(10.0,90.0) sind unterschiedlich
c.setX(10.0);c.setY(90.0);

assertFalse(a.punkteVergleichen(c));
}
}


How can I solve this problem?

Answer

Although the message may be a bit misleading, the JaCoCo Maven plugin will emit this warning when no tests have been run. This is your problem here: by default, the Maven Surefire Plugin executes tests that follow a particular naming convention, namely:

  • "**/Test*.java";
  • "**/*Test.java";
  • and "**/*TestCase.java".

But your test is named PunktUnitTests, with a trailing "s", and it causes it not to be executed. Thus, what happens is the following: the Surefire Plugin is not running any tests, so the JaCoCo agent is never used, and, as a result, the execution data file is not getting created.

The simple solution here is to rename your test according to the conventions of the Surefire Plugin, namely to PunktUnitTest.

Another solution would be to configure the plugin to execute your tests ending with "s":

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.19.1</version>
  <configuration>
    <includes>
      <include>**/*Tests.java</include>
    </includes>
  </configuration>
</plugin>

Note that if you want to prevent such errors in the future, you can configure the Surefire Plugin to fail if no tests are run, by setting the failIfNoTests parameter to true.

Comments