如何在Eclipse中使用运行方式> SWTBot测试来运行JUnit 5测试

问题描述 投票:2回答:1

我有一些使用SWTBot 2.8.0(在撰写本文时为最新版本)的非常简单的UI测试。这些都保存在Eclipse插件片段中,并且不使用任何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,然后尝试通过Run 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$0(E4Testable.java:76)
    at java.lang.Thread.run(Thread.java:748)

如果我中止执行,则出现<< [没有在Runner上找到测试: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标头以摆脱上述异常?

注:

相反,Run As> JUnit插件测试正确地初始化了测试运行器(JUnit视图显示带有Test.test的测试Runner: JUnit 5),然后冻结,当然,测试针对的是UI威胁,即no-go for SWTBot tests我有一些使用SWTBot 2.8.0(在撰写本文时为最新版本)的非常简单的UI测试。它们保存在Eclipse插件片段中,并且不使用任何JUnit 4细节,例如@ ...
junit eclipse-plugin eclipse-rcp junit5 swtbot
1个回答
0
投票
mailing list announcement称,[SWTBot将仅从SWTBot 3.0开始支持JUnit 5,该版本是Eclipse 2020-06的一部分发布。
© www.soinside.com 2019 - 2024. All rights reserved.