请帮我解决这个问题。我不太明白日志中的错误是什么意思。

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.749s
[INFO] Finished at: Thu Apr 24 10:10:20 IST 2014
[INFO] Final Memory: 15M/37M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test (default-test) on project samples.simpleforwarding: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.15:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?
[ERROR] Command wascmd.exe /X /C ""C:\Program Files\Java\jdk1.7.0_55\jre\bin\java" -Xmx1024m -XX:MaxPermSize=256m -jar E:\OpenDayLight\controller\opendaylight\samples\simpleforwarding\target\surefire\surefirebooter53410321571238933.jar E:\OpenDayLight\controller\opendaylight\samples\simpleforwarding\target\surefire\surefire86076271125218001tmp E:\OpenDayLight\controller\opendaylight\samples\simpleforwarding\target\surefire\surefire_01846991116135903536tmp"
[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

当前回答

在我的测试类中的一个静态成员变量调用一个方法来创建一个对象(在整个类的测试用例中使用),并且该方法导致了一个异常之后,我遇到了这个错误。

// Object created inside test class by calling a static getter.
// Exception thrown in getter:
private static Object someObject = SomeObject.getObject(...);

// ... <Object later used in class>

一些修复包括在每个测试用例中重新创建对象,并相应地捕获任何异常。或者通过在@BeforeTest方法中初始化对象并确保正确地构建对象。

其他回答

我在一个应用程序中遇到了同样的问题,即在运行测试时将大量XML记录到控制台。我认为这个问题与测试fork将其控制台日志发送到主maven线程以输出到屏幕的方式有关。

在我的测试日志文件中,我通过将有问题的类的日志设置为WARN来解决这个问题。

如logback-test.xml

<configuration debug="true">
  <include resource="org/springframework/boot/logging/logback/defaults.xml" />
  <include resource="org/springframework/boot/logging/logback/console-appender.xml" />

  <logger name="com.foo.ClassWithLotsOfXmlLogging" level="WARN" />

  <root level="INFO">
    <appender-ref ref="CONSOLE"/>
  </root>
</configuration>

在我的测试类中的一个静态成员变量调用一个方法来创建一个对象(在整个类的测试用例中使用),并且该方法导致了一个异常之后,我遇到了这个错误。

// Object created inside test class by calling a static getter.
// Exception thrown in getter:
private static Object someObject = SomeObject.getObject(...);

// ... <Object later used in class>

一些修复包括在每个测试用例中重新创建对象,并相应地捕获任何异常。或者通过在@BeforeTest方法中初始化对象并确保正确地构建对象。

在我的案例中,这个问题与IntelliJ IDEA控制台(OS windows 10)的日志输出时间过长有关。 命令:

mvn clean install

这个命令解决了我的问题:

mvn clean install > log-file.log

截至今天(2018年10月30日),我们注意到我们的构建在Jenkins中出现了这个错误。

这个错误有点误导人,需要查看target/surefire-reports/中转储的输出,才能看到以下错误消息:

Error: Could not find or load main class org.apache.maven.surefire.booter.ForkedBooter

这让我想到了下面的SO帖子,其中提到了OpenJDK 181中一个可能的错误:Maven surefire无法找到ForkedBooter类

那篇文章中的任何一个修复都解决了我的问题。具体来说,我使用了其中之一:

从docker容器maven:3.5.4-jdk-8中的构建切换到maven:3.5.4-jdk-8-alpine 重写Spring Boot的类加载器详细信息请参见:https://stackoverflow.com/a/50661649/1228408

最近travis终止了一个测试的执行(没有改变任何相关的东西(以及在开发人员机器上成功的构建!)),因此BUILD FAILURE。 原因之一是这样的(见@agudian的答案):

Surefire不支持调用System.exit()的测试或任何引用库

(因为测试类确实称为System.exit(-1))。

相反,使用简单的return语句会有所帮助。 为了让travis再次开心,我还必须添加@xiaohuo提供的surefire参数(<argLine>)。(此外,我必须删除-XX:MaxPermSize=256m,以便能够在我的一个台式机上构建)

只做这两件事中的一件是行不通的。

要了解更多背景知识,请阅读何时调用系统。退出Java。