如何使用Maven Tycho构建Junit5测试



我想向Junit5 Jupiter介绍一个旧的RCP测试片段。我们使用Maven Tycho构建我们的RCP功能。 从1.2版本开始,第谷应该支持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 依赖项存在,因为否则所有这些旧的单元测试将不再编译。

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

请参阅 https://wiki.eclipse.org/Tycho/How_Tos/JUnit5

诀窍似乎不是将 j5 添加为依赖项,而是通过导入包。

这对我有用。

最新更新