在弹簧中通过命令行运行时出错

时间:2013-06-12 04:37:49

标签: spring command-line junit

我有一个使用@Autowired注释和@ContextConfiguration以及@Category注释的测试类。

当测试通过日食时测试很好。 但是当我尝试通过命令行运行它时,它会抛出以下错误。

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.690s
[INFO] Finished at: Wed Jun 12 09:56:48 GMT+05:30 2013
[INFO] Final Memory: 31M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.14.1:integration-test (default) on project OmnitureSeleniumTests: Execution default of goal org.apache.maven.plugins:maven-failsafe-plugin:2.14.1:integration-test failed: There was an error in the forked process
[ERROR] java.lang.NoSuchMethodError: org.junit.runner.Request.classes(Lorg/junit/runner/Computer;[Ljava/lang/Class;)Lorg/junit/runner/Request;
[ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createReqestAndRun(JUnitCoreWrapper.java:128)
[ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:111)
 [ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:84)
[ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:138)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:597)
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
[ERROR] at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:159)
[ERROR] at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:87)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

我正在使用junit 4.8.2和 行家故障安全-插件:2.14.1

2 个答案:

答案 0 :(得分:0)

从Eclipse运行maven与命令行时可能存在许多配置/环境差异:

  1. maven版本/路径。在Eclipse中,实际的maven二进制文件可以通过首选项进行默认/显式设置,而在命令行中,您的操作系统将选择PATH环境变量中可用的第一个。使用mvn -version
  2. 检查maven版本
  3. Maven用户/全局settings.xml。通过命令行运行时,通常会使用〜/ .m2 / settings.xml,但这可以在Eclipse首选项上显式覆盖
  4. Maven本地存储库缓存。如果您在1和/或2上存在差异,则最终可能会使用不同的本地存储库缓存。如果针对不同的本地存储库缓存执行,则不正确的工件分发可能导致构建失败。
  5. Eclipse maven可以使用不同于命令行的JVM版本。

答案 1 :(得分:0)

我已将maven-failsafe-plugin的版本更改为2.6,并且它现在通过命令行正常运行:)