如何在 Eclipse 中使用 运行 As > SWTBot 测试 运行 JUnit 5 测试

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

我使用 SWTBot 2.8.0(在撰写本文时为最新版本)进行了一些非常简单的 UI 测试。这些保存在 Eclipse plug-in 片段中,不使用任何 JUnit 4 细节,如 @RunWith(SWTBotJunit4ClassRunner.class):

public class MyTest {

  private final SWTBot bot = new SWTBot();

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

现在,如果我从 org.junit.Test 切换到 JUnit 5 的 org.junit.jupiter.api.Test,然后尝试通过 运行 进行 运行 测试 As > SWTBot Test 我收到以下错误:

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[=13=](E4Testable.java:76)
    at java.lang.Thread.run(Thread.java:748)
如果我中止执行,

后跟 No Tests found with 运行ner: JUnit 5 消息。

我的 MANIFEST.MF 包含这些行:

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)"

我还需要添加什么到 Require-Bundle header 来摆脱上述异常?

注: 相比之下,运行as>JUnitPlug-inTest初始化测试运行ner 正确(JUnit 视图显示测试 Test.testRunner: JUnit 5)但随后冻结,当然 [=] 上的测试 运行 48=] 威胁,这是一个 no-go for SWTBot tests.

根据 mailing list announcement.

,SWTBot 将仅支持从 SWTBot 3.0 开始的 JUnit 5,作为 Eclipse 2020-06 的一部分发布