1

I'm working on creating a pom for a project and adding test cases to it. The project is an eclipse plugin.

Compiling the project with tycho works just fine, the only problem is during testing: If I run both maven-surefire-plugin tests and tycho-surefire-plugin-tests, the former performs all the tests as expected, while the latter gives the following error:

Execution test of goal org.eclipse.tycho:tycho-surefire-plugin:1.7.0:test failed: Tycho build extension not configured for MavenProject

I would be perfectly fine to just add <skipTests>true</skipTests> to the tycho-surefire-plugin while keeping maven-surefire-plugin on; the problem is even that way, jacoco refuses to create the coverage site, with the following (non error) message:

Skipping JaCoCo execution due to missing execution data file.

I tried to look for solutions of both, but any combination of the solutions I found doesn't lead me to having a working coverage site. Maven really makes me quite confused, especially with tycho around, so I'd apreciate any explanation on top of the actual fix.

Here is my pom:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
    
    <groupId>mygroupid</groupId>
    <artifactId>myartifactid</artifactId>
    <name>myname</name>
    <packaging>eclipse-test-plugin</packaging>
    
    <properties>
        <tycho-version>1.7.0</tycho-version>
    </properties>

    <parent>
        <groupId>parentgroupid</groupId>
        <artifactId>parent</artifactId>
        <version>0.9.5</version>
    </parent>
    
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.5</version>
        </dependency>
        
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
    </dependencies>

    <build>
        <testSourceDirectory>src/test/java/</testSourceDirectory>
        <plugins>
            

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                
                <configuration>
                </configuration>

                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <configuration>
                            <includes>
                                <include>**/Test_*.java</include>
                            </includes>
                        </configuration>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-surefire-plugin</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <configuration>
                            <includes>
                                <include>**/Test_*.java</include>
                            </includes>
                        </configuration>
                        <goals>
                            <goal>test</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <configuration>
                    <output>file</output>
                    <append>true</append>
                    <includes>
                        <include>**/path_to_source/**/*</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
         
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <executions>
                    <execution>
                        <id>compiletests</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

And here is my parent pom:

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>parentgroupid</groupId>
    <artifactId>parent</artifactId>
    <version>0.9.5</version>
    <packaging>pom</packaging>
    <modules>
        <module>moduleid</module>
    </modules>

    <properties>
        <tycho-version>1.7.0</tycho-version>
    </properties>

    <repositories>
     <repository>
         <id>eclipse-2020-06</id>
         <layout>p2</layout>
         <url>http://download.eclipse.org/releases/2020-06</url>
     </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>${tycho-version}</version>
                <extensions>true</extensions>
                
                <configuration>
                    <includeAllDependencies>true</includeAllDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
Barnack
  • 921
  • 1
  • 8
  • 20

2 Answers2

1

Of course there won't be any test result for the JaCoCo due to you are using very old Surefire version 2.12.4. This version was not created for JUnit5. Use the latest version 3.0.0-M5 and see the tutorial.

If you want to have tiny POM, remove the dependency junit-jupiter-engine due to you do not need to have an access to the JUnit internals in your test code. The Surefire will download it shortly before the test runtime.

tibor17
  • 1,043
  • 6
  • 9
  • If I apply your suggested version change I still get the "Skipping JaCoCo execution due to missing execution data file." I want to point out that maven.surefire tests work properly when I run "mvn verify". It still works fine after updating the version so I'll keep it to 3.0.0-M5; but the problem still persists – Barnack Oct 06 '20 at 15:42
  • 1
    I am the developer of Surefire plugins and I also use the JaCoCo plugin in our Apache project. IMO the problem is with `**/path_to_source/**/*`. Here should be the Java package of your classes located in src/main/java of the particular. Do not use physical paths. As an example this is a working example. Pls follow it, check it out and reply to me back with the result, or show me your project at the GitHub and I will have a look, see this hint https://github.com/apache/maven-surefire/blob/master/pom.xml#L570 – tibor17 Oct 06 '20 at 20:21
  • My include line (**/Test_*.java) matches all the test calsses names, which I have inside src/test/java (the source is inside src/main/java). During the test phase they're correctly detected, and when reaching surefire in maven execution I get "Tests run: 33, Failures: 0, Errors: 0, Skipped: 0". Maybe jacoco has issues because I'm skipping tycho surefire? EDIT: i changed the execution order so that jacoco executes right after maven-surefire, not after tycho-surefire, but the problem persists. I have surefire and jacoco working in other projects, only difference here is tycho – Barnack Oct 07 '20 at 14:21
  • https://github.com/Sephirothbahamut/tmp/ this is the repository; please note that it's not mine, i'm only supposed to add maven support and the test cases. It might not work with recent versions of Eclipse; i'm using Eclipse Luna and Eclipse IDE for Eclipse Committers(Version 2019-09 R (4.13.0)). – Barnack Oct 07 '20 at 15:54
  • please let me know if you're going to have a look at it; i'd really apreciate that – Barnack Oct 09 '20 at 02:09
  • I did check ou the project but I am not able to download the parent POM because it does not exit in the Maven Central. Se this error (after mvn verify): – tibor17 Oct 10 '20 at 17:26
  • [ERROR] The project it.unimi.di.adaptlab:de.ovgu.JavAdaptor:0.9.5 (C:\vcs\github\stackoverflow\pom.xml) has 1 error [ERROR] Non-resolvable parent POM for it.unimi.di.adaptlab:de.ovgu.JavAdaptor:0.9.5: Could not find artifact javadaptor:parent:pom:0.9.5 in central (https://repo.maven.apache.org/maven2) and 'parent.relativePath' points at wrong local POM @ line 16, column 10 – tibor17 Oct 10 '20 at 17:27
1

Your POM has several errors. Let's start with the root cause and then other priorities from high to low.

Whole problem is that Surefire does not know about JaCoCo. You have to tel "him" this way (see jacoco.agent) which "wires" both. Pls ead the documentation in the JaCoCo project:

<properties>
  <jvm.args.tests>-Xmx2048m -Xms1024m -XX:SoftRefLRUPolicyMSPerMB=50 -Djava.awt.headless=true -Djdk.net.URLClassPath.disableClassPathURLCheck=true</jvm.args.tests>
<properties>
...
      <artifactId>maven-surefire-plugin</artifactId>
      <configuration>
        <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
      </configuration>
...

The next error is with the way how you use plugins. The plugin jacoco-maven-plugin must be used only in the plugins section. The problem is that you use it also in the dependencies section. You do not want to have it on the classpath. It is job of the property jacoco.agent to put the jacoco agent on the test classpth only but there the JaCoCo plugin must start before the Surefire plugin.

The next thing i do not understand is the config of the compiler. Why you have this?

             <executions>
                <execution>
                    <id>compiletests</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>

I have second question regarding the packaging. I have never seen this one. It isn't a standard packaging.

<packaging>eclipse-test-plugin</packaging>

Has the Eclipse plugin any special binary form of the archive file?

tibor17
  • 1,043
  • 6
  • 9
  • I updated the repo. "parent_pom" has to be put in the parent directory. "other_pom" is the pom i've been using in another project without tycho; as you can see jacoco and surefire are the same in the project's pom and in "other_pom". The only big different is that this project uses tycho. So i either missed something stupid, or tycho is messing up things. "eclipse-test-plugin" is for eclipse plugins; tycho is supposed to automatically manage some eclipse plugins dependencies (example i dont have to specify the javassist dependency in the pom with tycho and it still compiles fine) – Barnack Oct 15 '20 at 12:57