【问题标题】:How to build Junit5 tests w/ Maven Tycho如何使用 Maven Tycho 构建 Junit5 测试
【发布时间】:2018-12-10 20:30:54
【问题描述】:

我想将 Junit5 Jupiter 介绍给旧的 RCP 测试片段。我们使用 Maven Tycho 构建我们的 RCP 功能。 从 1.2 版开始,Tycho 应该支持 JUnit5 测试。

我得到的只是(当我运行 mvn clean install 时)

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.AbstractUITestApplication.runTests(AbstractUITestApplication.java:44)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Testable.lambda$0(E4Testable.java:73)
    at java.lang.Thread.run(Thread.java:748)
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)
    ... 7 more

这些是我在 Manifest.MF 中的依赖项:

 org.junit.jupiter.api;bundle-version="5.0.0",
 org.junit.jupiter.engine;bundle-version="5.0.0",
 org.junit.jupiter.params;bundle-version="5.0.0",
 org.junit.jupiter.migrationsupport;bundle-version="5.0.0",
 org.junit.vintage.engine;bundle-version="4.12.0",
 org.hamcrest.core;bundle-version="1.3.0",
 org.junit;bundle-version="4.12.0",
 org.opentest4j,
 org.junit.platform.commons;bundle-version="1.0.0",
 org.junit.platform.engine;bundle-version="1.0.0",
 org.junit.platform.launcher;bundle-version="1.0.0",
 org.junit.platform.runner;bundle-version="1.0.0",
 org.junit.platform.suite.api;bundle-version="1.0.0"

我主要通过反复试验来添加这些依赖项。如果我也想在 Eclipse 中运行 J5 测试,我知道我需要这些平台包。 在 Eclipse 中,新旧测试都可以正常工作。

junit 4.12 依赖项存在,否则所有那些旧的单元测试将不再编译。

有没有关于如何使用 Tycho 进行 Junit5 测试的示例? 也许我在谷歌上搜索错误的东西;)

【问题讨论】:

    标签: eclipse rcp tycho junit5


    【解决方案1】:

    https://wiki.eclipse.org/Tycho/How_Tos/JUnit5

    诀窍似乎不是将 j5 添加为依赖项,而是通过 import-package。

    这对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-13
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 2015-11-28
      • 1970-01-01
      • 2017-09-16
      相关资源
      最近更新 更多