Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 534587

Summary: Junit5 Tests no longer work (worked with 1.1)
Product: z_Archived Reporter: Christian Dietrich <christian.dietrich.opensource>
Component: TychoAssignee: Project Inbox <tycho-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: clement.hurlin, gunnar, jan.sievers, karsten.thoms, Martin.SCHREIBER, thatnitind
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard:
Attachments:
Description Flags
Sample Project
none
Log File
none
Complete Export none

Description Christian Dietrich CLA 2018-05-11 12:17:02 EDT
out junit5 tests that worked before with tycho 1.1 do not work with the current 1.2 Snapshot
Comment 1 Christian Dietrich CLA 2018-05-11 12:17:44 EDT
Created attachment 274005 [details]
Sample Project
Comment 2 Christian Dietrich CLA 2018-05-11 12:20:07 EDT
Created attachment 274006 [details]
Log File
Comment 3 Martin Schreiber CLA 2018-05-14 01:21:58 EDT
Christian, the example project is only a target-definition project without any tests and the parent pom is missing. It would be great if you could attach a project that could be used without modifications/additions to be sure to have the same setup as you do.
Comment 4 Christian Dietrich CLA 2018-05-14 01:27:39 EDT
arggg  i exported the wrong project ....
Comment 5 Christian Dietrich CLA 2018-05-14 01:42:53 EDT
Created attachment 274021 [details]
Complete Export

Attached new and Complete Sample Project
Comment 6 Jan Sievers CLA 2018-05-14 05:08:57 EDT
I am wondering how JUnit 5 tests could ever have worked in Tycho 1.1 if we added support for JUnit 5 in Tycho 1.2-SNAPSHOT only (bug 522475) ?
Comment 7 Christian Dietrich CLA 2018-05-14 06:42:33 EDT
indeed. working means "not explode"
anyway: the junit5 bugilla is closed so i wonder what i am mising
Comment 8 Jan Sievers CLA 2018-05-14 07:56:13 EDT
!ENTRY org.eclipse.osgi 4 0 2018-05-11 18:18:54.264
!MESSAGE Application error
!STACK 1
org.apache.maven.surefire.util.SurefireReflectionException: java.util.ServiceConfigurationError: org.junit.platform.engine.TestEngine: Provider org.junit.jupiter.engine.JupiterTestEngine not a subtype
	at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:135)
	at org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:276)
	at org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:113)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:81)
	at org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.run(OsgiSurefireBooter.java:107)
	at org.eclipse.tycho.surefire.osgibooter.HeadlessTestApplication.run(HeadlessTestApplication.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1498)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1471)
Caused by: java.util.ServiceConfigurationError: org.junit.platform.engine.TestEngine: Provider org.junit.jupiter.engine.JupiterTestEngine not a subtype
	at java.util.ServiceLoader.fail(ServiceLoader.java:239)
	at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
	at org.junit.platform.launcher.core.DefaultLauncher.validateUniqueIds(DefaultLauncher.java:63)
	at org.junit.platform.launcher.core.DefaultLauncher.<init>(DefaultLauncher.java:58)
	at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:59)
	at org.junit.platform.surefire.provider.JUnitPlatformProvider.<init>(JUnitPlatformProvider.java:85)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:131)
	... 23 more




sounds to me like a class incompatibility between Junit5 classes shipped with Tycho surefire and the ones directly referenced in the test plugin

our premise was that test plugins only require the JUnit 5 API packages, not any concrete engine providers.

See bug 522475 comment 14

I see in your test bundle org.xtext.example.mydsl6.tests

Require-Bundle: 
 org.junit.jupiter.engine;bundle-version="5.1.0",
 org.junit.platform.commons;bundle-version="1.1.0",
 org.junit.platform.engine;bundle-version="1.1.0",
 org.opentest4j;bundle-version="1.0.0",


are these really required?
Comment 9 Karsten Thoms CLA 2018-05-14 08:18:27 EDT
I have to check the dependencies. IIRC I had difficulties running tests from within Eclipse without them. Since JU5 allows different engines, how should it decide which one to run if not decided on classpath?

Will come back on this when having time to check it.
Comment 10 Christian Dietrich CLA 2018-05-14 08:19:20 EDT
for me the launch as stuff does not work in eclipse when not having these dependencies (+ even an additional one)
Comment 11 Jan Sievers CLA 2018-05-14 09:42:34 EDT
(In reply to Christian Dietrich from comment #10)
> for me the launch as stuff does not work in eclipse when not having these
> dependencies (+ even an additional one)

IIRC if they are runtime-only deps, they should not be required by the test bundle itself

see https://junit.org/junit5/docs/current/user-guide/#dependency-metadata-junit-jupiter

for now there are 2 engines, jupiter and vintage (for running JUnit3/4 tests) and Tycho brings both of them so no need to require them

you can add them to the target platform of your JUnit launch configuration

One could argue that the JUnit 5 launch config should be smart enough to add the required JUnit5 runtime bundles from the target platform if "Test Runner: JUnit5" is selected, see

https://www.eclipse.org/eclipse/news/4.7.1a/#junit-5-support

bug 530031 , bug 526502 seem related
Comment 12 Christian Dietrich CLA 2018-05-16 17:36:05 EDT
yes it works if we dont provide the engine ourselves
Comment 13 Karsten Thoms CLA 2018-05-16 18:36:00 EDT
Thanks Jan for pointing us in the right direction. I think we can close that issue.
Comment 14 Gunnar Wagenknecht CLA 2018-11-09 15:06:21 EST
Karsten, Christian, Jan, I think this warrants some more info on the wiki page.

I followed what's written here to get it working with Tycho. 
https://wiki.eclipse.org/Tycho/How_Tos/JUnit5

Now Tycho is happy. But Eclipse is not.

I'm unable to launch a JUnit launch configuration for a test in the same project. It complains: "Cannot find class 'org.junit.platform.commons.annotation.Testable' on project build path."

Any recommendations how to best set it up?
Comment 15 Gunnar Wagenknecht CLA 2019-02-25 13:22:51 EST
Sight. At some point I had it working. New project today with Tycho 1.3 and no tests found. Steps to reproduce at bug 544789.
Comment 16 Clément Hurlin CLA 2019-05-14 17:36:35 EDT
Gunnar> I'm in the same position (using Eclipse-2019-03). Having:

Import-Package: org.junit,
 org.junit.jupiter.api

makes tycho happy but I don't have "Run As > JUnit test" within Eclipse. Having:

Require-Bundle: org.junit,
 org.junit.jupiter.api,
 org.junit.jupiter.engine,
 org.junit.jupiter.migrationsupport,
 org.junit.jupiter.params,
 org.junit.platform.commons,
 org.junit.platform.engine,
 org.junit.platform.launcher,
 org.junit.platform.runner,
 org.junit.platform.suite.api,
 org.hamcrest.core,
 org.opentest4j,
 org.apiguardian

makes Eclipse happy ("Run As > JUnit Test" shows up and works fine)(I found this "Require-Bundle" clause by using the "New > JUnit Test Case" wizard).

However, I need both usages: tycho on the command line for CI and "Run As" within Eclipse for day-to-day testing.

Any help is appreciated.
Comment 17 Clément Hurlin CLA 2019-05-16 05:52:28 EDT
Gunnar> Thanks to Christian's help, I found out that I was missing the JUnit library in my .classpath: <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>

I now have "Run As > JUnit Test" that works within Eclipse and using the "Import-Package" above makes it work from tycho (pomless build).

For the record, modifying the .classpath should make this entry visible in Eclipse: https://i.imgur.com/67kURAo.png. This is done with the GUI as follows: https://i.imgur.com/bOXK0Uu.png.