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

时间:2019-03-05 09:13:16

标签: java eclipse maven junit rcp

我有一个Maven3多模块RCP Eclipse项目。我想从Maven运行JUnit测试。具有JUnit测试的模块是eclipse插件。我尝试通过在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>

使用mvn test不会触发测试。仅编译类。 使用mvn verify时出现以下错误:

  

-------------------------------------------------- --------测试   -------------------------------------------------- - - - 发生了错误。看看日志文件   E:\ Git \ EF8_Toolcenter_repository_custom \ de.audi.eftc.platform.contact \ target \ work \ data.metadata.log。

     

[错误]无法执行目标   org.eclipse.tycho:tycho-surefire-plugin:0.24.0:test(默认测试)   项目xxxx.contact:启动该项目时发生意外错误   测试运行时(返回代码13)。有关详细信息,请参见日志。 -> [帮助1]

日志包含:

  

!会议2019-03-05 11:31:23.457   ----------------------------------------------- eclipse.buildId =未知的java.version = 1.8.0_191 java.vendor = Oracle   公司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   -应用程序org.eclipse.tycho.surefire.osgibooter.headlesstest -testproperties   xxxx \ target \ surefire.properties

     

!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”未解决的要求:导入包:   junit.framework;版本=“ 3.0.0”

     

!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.surefire.junit4.JUnit4Provider位于   org.apache.maven.surefire.util.ReflectionUtils.loadClass(ReflectionUtils.java:251)     在   org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:128)     在   org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:235)     在   org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:113)     在   org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:78)     在   org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.run(OsgiSurefireBooter.java:91)     在   org.eclipse.tycho.surefire.osgibooter.HeadlessTestApplication.run(HeadlessTestApplication.java:21)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.eclipse.equinox.internal.app.EclipseAppContainer.callMethodWithException(EclipseAppContainer.java:587)     在   org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:198)     在   org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)     在   org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)     在   org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)     在   org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)位于   org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)在   org.eclipse.equinox.launcher.Main.run(Main.java:1498)在   org.eclipse.equinox.launcher.Main.main(Main.java:1471)由以下原因引起:   java.lang.ClassNotFoundException:   org.apache.maven.surefire.junit4.JUnit4Provider位于   org.eclipse.tycho.surefire.osgibooter.CombinedClassLoader.findClass(CombinedClassLoader.java:37)     在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个

我在做什么错? 预先谢谢你!

1 个答案:

答案 0 :(得分:0)

我已经找出了问题所在。我不得不在MANIFEST.MForg.junit中加入依赖关系。