juniteclipse-plugineclipse-rcpjunit5swtbot

How to run JUnit 5 Tests using Run As > SWTBot Tests in Eclipse


I have a couple of really simple UI tests using SWTBot 2.8.0 (at the time of writing, the latest release). These are kept in an Eclipse plug-in fragment and do not use any JUnit 4 specifics like @RunWith(SWTBotJunit4ClassRunner.class):

public class MyTest {

  private final SWTBot bot = new SWTBot();

  @Test
  public void test() {
    // …
  }
}

Now if I switch from org.junit.Test to JUnit 5's org.junit.jupiter.api.Test and then try to run the tests via Run As > SWTBot Test I get the following error:

Exception in thread "WorkbenchTestable" java.lang.IllegalArgumentException: Error: test loader org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader not found:
org.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath
    at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:295)
    at org.junit.platform.launcher.core.DefaultLauncher.<init>(DefaultLauncher.java:58)
    at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:91)
    at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:67)
    at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.<init>(JUnit5TestLoader.java:34)
    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 java.lang.Class.newInstance(Class.java:442)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:370)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:365)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:309)
    at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.init(RemotePluginTestRunner.java:85)
    at org.eclipse.swtbot.eclipse.core.RemotePluginTestRunner.main(RemotePluginTestRunner.java:63)
    at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(UITestApplication.java:120)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Testable.lambda$0(E4Testable.java:76)
    at java.lang.Thread.run(Thread.java:748)

followed by a No Tests found with Runner: JUnit 5 message if I abort the execution.

My MANIFEST.MF contains these lines:

Require-Bundle: org.eclipse.swtbot.swt.finder;bundle-version="[2.7.0,3.0.0)",
 org.junit;bundle-version="[4.12.0,5.0.0)",
 org.junit.jupiter.api;bundle-version="[5.4.0,6.0.0)",
 org.junit.jupiter.engine;bundle-version="[5.4.0,6.0.0)"

What else do I need to add to the Require-Bundle header to get rid of the above exception?

Note: In contrast, Run As > JUnit Plug-in Test initializes the test runner correctly (the JUnit view shows test Test.test with Runner: JUnit 5) but then freezes, as of course the tests run on the UI threat, which is a no-go for SWTBot tests.


Solution

  • SWTBot will only support JUnit 5 starting with SWTBot 3.0, released as part of Eclipse 2020-06, according to the mailing list announcement.