简体   繁体   English

在来自Maven的eclipse-test-plugins上运行JUnit测试

[英]Running JUnit tests on eclipse-test-plugins from maven

I have a maven3 multi-module RCP eclipse project. 我有一个Maven3多模块RCP Eclipse项目。 I want to run JUnit tests from maven. 我想从Maven运行JUnit测试。 The modules that have JUnit tests are eclipse-plugins. 具有JUnit测试的模块是eclipse插件。 I've tried to run them using Tycho Surefire Plugin by adding this at pom file: 我试图通过在pom文件中添加以下代码来使用Tycho Surefire Plugin运行它们:

    <packaging>eclipse-test-plugin</packaging>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
  <build>
    <sourceDirectory>src/test</sourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-surefire-plugin</artifactId>
        <version>0.24.0</version>
        <configuration>
          <includes>
              <include>**/*Test.java</include>
          </includes>
          <useUIHarness>false</useUIHarness>
          <providerHint>junit4</providerHint>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

With mvn test the tests are not triggered. 使用mvn test不会触发测试。 Only the classes are compiled. 仅编译类。 With mvn verify I get the following error: 使用mvn verify ,出现以下错误:

------------------------------------------------------- TESTS ------------------------------------------------------- An error has occurred. -------------------------------------------------- -----测试-------------------------------------------- - - - - - - 发生了错误。 See the log file E:\\Git\\EF8_Toolcenter_repository_custom\\de.audi.eftc.platform.contact\\target\\work\\data.metadata.log. 请参阅日志文件E:\\ Git \\ EF8_Toolcenter_repository_custom \\ de.audi.eftc.platform.contact \\ target \\ work \\ data.metadata.log。

[ERROR] Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:0.24.0:test (default-test) on project xxxx.contact: An unexpected error occured while launching the test runtime (return code 13). [错误]无法在项目xxxx.contact上执行目标org.eclipse.tycho:tycho-surefire-plugin:0.24.0:test(默认测试)。contact:启动测试运行时发生意外错误(返回码13)。 See log for details. 有关详细信息,请参见日志。 -> [Help 1] -> [帮助1]

The log contains: 日志包含:

!SESSION 2019-03-05 11:31:23.457 ----------------------------------------------- eclipse.buildId=unknown java.version=1.8.0_191 java.vendor=Oracle Corporation BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US Framework arguments: -application org.eclipse.tycho.surefire.osgibooter.headlesstest -testproperties xxxx\\target\\surefire.properties Command-line arguments: -data xxxx\\target\\work\\data -application org.eclipse.tycho.surefire.osgibooter.headlesstest -testproperties xxxx\\target\\surefire.properties !SESSION 2019-03-05 11:31:23.457 -------------------------------------- --------- eclipse.buildId =未知的java.version = 1.8.0_191 java.vendor = Oracle Corporation BootLoader常数:OS = win32,ARCH = x86_64,WS = win32,NL = zh_CN框架参数:-application org.eclipse.tycho.surefire.osgibooter.headlesstest -testproperties xxxx \\ target \\ surefire.properties命令行参数:-data xxxx \\ target \\ work \\ data -application org.eclipse.tycho.surefire.osgibooter.headlesstest -testproperties xxxx \\目标\\ surefire.properties

!ENTRY org.eclipse.tycho.surefire.junit4 2 0 2019-03-05 11:31:24.892 !MESSAGE Could not resolve module: org.eclipse.tycho.surefire.junit4 [134] Unresolved requirement: Import-Package: junit.framework; !ENTRY org.eclipse.tycho.surefire.junit4 2 0 2019-03-05 11:31:24.892!MESSAGE无法解析模块:org.eclipse.tycho.surefire.junit4 [134]未解决的要求:进口包装:junit .framework; version="3.0.0" Unresolved requirement: Import-Package: junit.framework; version =“ 3.0.0”未解决的要求:导入包:junit.framework; version="3.0.0" 版本= “3.0.0”

!ENTRY org.eclipse.osgi 4 0 2019-03-05 11:31:24.893 !MESSAGE Application error !STACK 1 org.apache.maven.surefire.util.SurefireReflectionException: java.lang.ClassNotFoundException: org.apache.maven.surefire.junit4.JUnit4Provider at org.apache.maven.surefire.util.ReflectionUtils.loadClass(ReflectionUtils.java:251) at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:128) at org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:235) at org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:113) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:78) at org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.run(OsgiSurefireBooter.java:91) at org.eclipse.tycho.surefire.osgibooter.HeadlessTestApplication.run(HeadlessTestApplication.java:21) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke !ENTRY org.eclipse.osgi 4 0 2019-03-05 11:31:24.893!消息应用程序错误!堆栈1 org.apache.maven.surefire.util.SurefireReflectionException:java.lang.ClassNotFoundException:org.apache.maven。位于org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:128)的org.apache.maven.surefire.util.ReflectionUtils.loadClass(ReflectionUtils.java:251)的surefire.junit4.JUnit4Provider org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:113)上的apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:235)在org.apache.maven.surefire.booter上。 org.eclipse.tycho.surefire.osgibooter.HeadlessTestApplication.run(HeadlessTestApplication.java:上的ProviderFactory.invokeProvider(ProviderFactory.java:78)在org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.run(OsgiSurefireBooter.java:91) 21)at sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.in (NativeMethodAccessorImpl.java:62),位于org.eclipse.equinox.internal.app的java.lang.reflect.Method.invoke(Method.java:498),位于sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)。 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.org)上的org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198)上的EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587) java:134)位于org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)位于org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388) .eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)位于sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) .DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在java.lang.reflect.Method.in voke(Method.java:498) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:592) at org.eclipse.equinox.launcher.Main.run(Main.java:1498) at org.eclipse.equinox.launcher.Main.main(Main.java:1471) Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.junit4.JUnit4Provider at org.eclipse.tycho.surefire.osgibooter.CombinedClassLoader.findClass(CombinedClassLoader.java:37) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.apache.maven.surefire.util.ReflectionUtils.loadClass(ReflectionUtils.java:243) ... 24 more 在org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)在org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)在org.eclipse。 org.eclipse.equinox.launcher.Main.main(Main.java:1471)处的.equinox.launcher.Main.run(Main.java:1498)原因:java.lang.ClassNotFoundException:org.apache.maven.surefire org.eclipse.tycho.surefire.osgibooter.CombinedClassLoader.findClass(CombinedClassLoader.java:37)上的.junit4.JUnit4Provider位于java.lang.ClassLoader.loadClass(ClassLoader.java:424)上的java.lang.ClassLoader.loadClass(ClassLoader .java:357),位于org.apache.maven.surefire.util.ReflectionUtils.loadClass(ReflectionUtils.java:243)...还有24个

What am I doing wrong? 我究竟做错了什么? Thank you in advance! 先感谢您!

I've figured out what was the problem. 我已经找出了问题所在。 I had to put to dependencies in MANIFEST.MF also the org.junit . 我不得不在MANIFEST.MF以及org.junit添加依赖项。

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

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