maveneclipse-pluginjunit5eclipse-jdttycho

Tycho does not find JUnit5 tests since Eclipse 2022-09


I've migrated from Eclipse 2022-06 to 2022-09, and now Tycho doesn't find my tests. My environment, setup, and test code are provided below.

Environment

Running mvn -v results in

Java version: 17.0.6, vendor: Eclipse Adoptium, runtime: C:\Program Files\Eclipse Adoptium\jdk-17.0.6.10-hotspot
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Setup (Works Fine)

I followed the instructions at https://wiki.eclipse.org/Tycho/How_Tos/JUnit5 (except I use newer Java and Tycho versions), and the tests run successfully with Eclipse 2022-06. When I change the repository URL to use 2022-09, Tycho doesn't find the tests.

FooTest.java:

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class FooTest {
    @Test
    public void junit5Test() {
        Assertions.assertTrue(true);
    }
}

MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: De Foobar Tests
Bundle-SymbolicName: de.foobar.tests;singleton:=true
Bundle-Version: 1.0.0.qualifier
Import-Package: org.junit;version="4.0.0",
 org.junit.jupiter.api;version="5.0.0"
Bundle-Vendor: Foobar Inc
Bundle-RequiredExecutionEnvironment: JavaSE-17

pom.xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <artifactId>de.foobar.tests</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>de.foobar.tests</name>
    <groupId>groobar</groupId>
    <packaging>eclipse-test-plugin</packaging>
    <properties>
        <tycho-version>2.7.4</tycho-version>
    </properties>
    <repositories>
        <repository>
            <id>eclipse-release</id>
            <layout>p2</layout>
            <url>https://download.eclipse.org/releases/2022-06</url>
        </repository>
    </repositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>${tycho-version}</version>
                <extensions>true</extensions>
            </plugin>
        </plugins>
    </build>
</project>

When I now run mvn clean verify, the console prints

Results:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] All tests passed!
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Problem (Change Setup to Break)

When I replace <url>https://download.eclipse.org/releases/2022-06</url> with <url>https://download.eclipse.org/releases/2022-09</url> and run mvn clean verify again, the console prints:

Results:

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  16.459 s
[INFO] Finished at: 2023-05-04T11:45:41+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:2.7.4:test (default-test) on project de.foobar.tests: No tests found. -> [Help 1]

Question

Why are the tests not found? How to fix this?

I also tried adding "org.junit.jupiter.engine.execution" as package import because it provides the test executors. But the org.eclipse.tycho:tycho-compiler-plugin:2.7.4:validate-classpath goal will print Unresolved requirement: Import-Package: org.junit.jupiter.engine.execution which I don't understand either, because the package is provided by the junit-jupiter-engine JAR that is available on the p2 repo.

Some further information:


Solution

  • I was able to resolve the issue by updating Tycho to the latest version (3.x instead of 2.x). I want to give credit to @greg-449, the legend, for the helpful suggestion.