0

This might be two different problems, but I suspect both related to tycho, this is why I ask them together.

I have a project using eclipse-test-plugin packaging. As I could not get tycho-surefire-plugin working (see obtaining spring annotation context in tycho-surefire-test ), I resorted to unit tests. They run fine using eclipse, and initially with maven as well. After a tycho version update, the tests started not to run. I guess it has something to do how tycho-maven-plugin changes execution of plugins.

I could get maven-surefire-plugin to run using explicit <execution> tag, but now it says Using auto detected provider org.apache.maven.surefire.junit4.JUnit4Provider, and does not find the tests. Even when I added junit-jupiter-engine and (perhaps redundantly) junit-jupiter-api as plugin dependencies, as the documentation said.

mvn dependency:tree does not show anything junit 4 related, however the target platform contains org.eclipse.jdt.junit4.runtime.jar.

What happens here and how could I run my unit tests using maven?

Here is everything from the effective pom which I think could be related to the problem:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <packaging>eclipse-test-plugin</packaging> <dependencyManagement> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.14.0</version> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.14.0</version> </dependency> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-launcher</artifactId> <version>1.14.0</version> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>5.20.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>3.5.6</version> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.14.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.14.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-launcher</artifactId> <version>1.14.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>6.2.11</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>5.20.0</version> <scope>compile</scope> </dependency> </dependencies> <build> <pluginManagement> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-maven-plugin</artifactId> <version>4.0.12</version> <extensions>true</extensions> </plugin> </plugins> </pluginManagement> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>3.5.4</version> <executions> <execution> <id>plain-unit-tests</id> <phase>test</phase> <goals> <goal>test</goal> </goals> <configuration> <exclude>**/*PluginTest.class</exclude> <skip>false</skip> <failIfNoTests>true</failIfNoTests> <testClassesDirectory>/home/mag/project/KodeKonveyor/inez-server/inez.parser.tests/target/classes</testClassesDirectory> </configuration> </execution> </executions> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-engine</artifactId> <version>5.14.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.14.0</version> <scope>compile</scope> </dependency> </dependencies> <configuration> <skip>false</skip> <failIfNoTests>true</failIfNoTests> <testClassesDirectory>/home/mag/project/KodeKonveyor/inez-server/inez.parser.tests/target/classes</testClassesDirectory> </configuration> </plugin> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-surefire-plugin</artifactId> <version>4.0.12</version> <executions> <execution> <id>default-test</id> <phase>integration-test</phase> <goals> <goal>test</goal> </goals> <configuration> <skip>true</skip> <bundleStartLevel> <bundle> <id>io.github.magwas.inez.parser</id> <level>1</level> <autoStart>true</autoStart> </bundle> </bundleStartLevel> </configuration> </execution> </executions> <configuration> <skip>true</skip> <bundleStartLevel> <bundle> <id>io.github.magwas.inez.parser</id> <level>1</level> <autoStart>true</autoStart> </bundle> </bundleStartLevel> </configuration> </plugin> </plugins> </build> </project> 
6
  • 1
    That's not how it works. See this tutorial how it works: vogella.com/tutorials/EclipseTycho/… - example project with different kinds of tests: github.com/vogellacompany/tycho-example Commented Oct 14 at 12:35
  • Why using tycho for a spring boot based project? Why defining the junit jupiter with literal versions instead of using them which are coming from Spring Boot? Why using literal hard coded directories like <testClassesDirectory>/home/mag/project/KodeKonveyor/inez-server/inez.parser.tests/target/classes</testClassesDirectory> </configuration> which does not make sense at all... Where is JUnit 4 ? technically you can execute JUnit 4 based tests via the vintage engine of JUnit Jupiter but it does not make sense because JUnit 4 is out of date ... use JUnit Jupiter (aka JUnit 5 or 6).... Commented Oct 14 at 14:52
  • @howlger what exactly is not supposed to work this way? The tutorial you linked does not address a bunch of real life questions, for example the question of how to have a classloader which actually resolves classes. (Yes, the dependencies are part of the target definition and declared in MANIFEST.MF, and things are resolved in production code, but not in the tests.) My question wasn't about how it does not work, but partly about how a tycho build differs from a normal maven build, so I can figure out why those things which work with maven and older tycho versions suddenly stopped working. Commented Oct 14 at 17:04
  • @khmarbaise Why I should not use spring in an eclipse plugin? Spring is responsible for DI within the bundles, and OSGI is responsible for DI between them. It is supposed to work, and does work in the production code, but produces quite strange effects in tests. Commented Oct 14 at 17:07
  • @khmarbaise the literal hard coded directories there because it is from the effective pom, as the project's pom have 4 layers of parents, and I did not want to complicate the question with throwing in 2000 lines of 5 pom.xml files. The question of where is junit 4 is exactly what I am asking, because I see no reason for junit 4 to show up here, exactly because it is obsolete. Commented Oct 14 at 17:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.