有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在maven的eclipsetestplugins上运行JUnit测试

我有一个maven3多模块RCP eclipse项目。我想从maven运行JUnit测试。具有JUnit测试的模块是eclipse插件。我尝试使用Tycho Surefire Plugin在pom文件中添加以下内容来运行它们:

    <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我得到以下错误:

------------------------------------------------------- T E S T S ------------------------------------------------------- An error has occurred. See the log file 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). See log for details. -> [Help 1]

日志包含:

!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

!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; version="3.0.0" Unresolved requirement: Import-Package: junit.framework; version="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(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.invoke(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

我做错了什么? 提前谢谢你


共 (1) 个答案

  1. # 1 楼答案

    我已经知道问题出在哪里了。我必须在MANIFEST.MF中添加依赖项,也必须在org.junit中添加依赖项