简体   繁体   English

如何使用Maven Tycho构建Junit5测试

[英]How to build Junit5 tests w/ Maven Tycho

I want to introduce Junit5 Jupiter to an old RCP test fragment. 我想向旧的RCP测试片段介绍Junit5 Jupiter。 We build our RCP features w/ Maven Tycho. 我们使用Maven Tycho构建RCP功能。 Since version 1.2, Tycho is supposed to support JUnit5 tests. 从1.2版开始,Tycho应该支持JUnit5测试。

All I get is (when I run mvn clean install ) 我得到的只是(当我运行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

These are my dependencies from the Manifest.MF: 这些是我对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"

I added those dependencies mostly by trial and error. 我主要通过反复试验添加了这些依赖项。 I know I need those platform bundles if I want to run the J5 tests in Eclipse, too. 我知道如果我也想在Eclipse中运行J5测试,则需要这些平台捆绑软件。 In Eclipse, both the old and the new tests work fine. 在Eclipse中,新旧测试都可以正常工作。

The junit 4.12 dependency is there because otherwise all those old unit tests won't compile anymore. 存在junit 4.12依赖项,因为否则所有这些旧的单元测试将不再编译。

Is there an example on how to get Junit5 tests going using Tycho? 是否有示例说明如何使用Tycho进行Junit5测试? Maybe I am googling the wrong stuff ;) 也许我在搜索错误的东西;)

See https://wiki.eclipse.org/Tycho/How_Tos/JUnit5 参见https://wiki.eclipse.org/Tycho/How_Tos/JUnit5

The trick seems to be not to add j5 as dependencies but by import-package. 诀窍似乎不是将j5添加为依赖项,而是通过import-package添加。

This worked for me. 这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM