java - Surefire Maven 插件 : "Corrupted STDOUT by directly writing to native stream in forked JVM"

标签 java maven junit maven-surefire-plugin

我的 JUnit 测试在通过 Maven 和 Surefire 插件(下面的版本信息)运行时失败了。我看到错误消息:

Corrupted STDOUT by directly writing to native stream in forked JVM 4. See FAQ web page and the dump file C:\(...)\target\surefire-reports\2019-03-20T18-57-17_082-jvmRun4.dumpstream

FAQ 页面指出了一些可能的原因,但我不知道如何使用这些信息来开始解决这个问题:

Corrupted STDOUT by directly writing to native stream in forked JVM

If your tests use native library which prints to STDOUT this warning message appears because the library corrupted the channel used by the plugin in order to transmit events with test status back to Maven process. It would be even worse if you override the Java stream by System.setOut because the stream is also supposed to be corrupted but the Maven will never see the tests finished and build may hang.

This warning message appears if you use FileDescriptor.out or JVM prints GC summary.

In that case the warning is printed "Corrupted STDOUT by directly writing to native stream in forked JVM", and a dump file can be found in Reports directory.

If debug level is enabled then messages of corrupted stream appear in the console.

它指的是一些直接打印到 STDOUT 的 native 库,但我如何才能确定是哪一个,即使我知道,如果我的项目需要该库,我该如何处理这个问题?

它提到“调试级别”,但不清楚这是指 Maven 的调试级别还是 Surefire 插件的调试级别。我启用了 Maven 的调试,但没有看到常见问题解答中提到的控制台输出。 Surefire 的调试选项似乎是关于暂停测试并等待调试器连接到进程,而不是简单地在控制台上显示更多信息。

转储文件似乎也不是很有用:

# Created on 2019-03-20T18:42:58.323
Corrupted STDOUT by directly writing to native stream in forked JVM 2. Stream 'FATAL ERROR in native method: processing of -javaagent failed'.
java.lang.IllegalArgumentException: Stream stdin corrupted. Expected comma after third character in command 'FATAL ERROR in native method: processing of -javaagent failed'.
    at org.apache.maven.plugin.surefire.booterclient.output.ForkClient$OperationalData.<init>(ForkClient.java:511)
    at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.processLine(ForkClient.java:209)
    at org.apache.maven.plugin.surefire.booterclient.output.ForkClient.consumeLine(ForkClient.java:176)
    at org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer$Pumper.run(ThreadedStreamConsumer.java:88)
    at java.base/java.lang.Thread.run(Thread.java:834)

那么,我该如何解决这个问题呢?

更新:请求配置信息如下。

我在 Windows 10、Maven 3.5.3 和 Surefire 2.21.0(下面的完整配置)上使用 OpenJDK 11(Zulu 发行版)。

我使用 pom.xml 文件上的“Run As...”上下文菜单选项从 Eclipse 运行 Maven,但在控制台上运行它时获得相同的结果。

在对这个问题发表第一条评论之前,我从未听说过 JaCoco,但我看到几条提到它的错误消息:

[ERROR] ExecutionException The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was cmd.exe /X /C ""C:\Program Files\Zulu\zulu-11\bin\java" -javaagent:C:\\Users\\E26638\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.0\\org.jacoco.agent-0.8.0-runtime.jar=destfile=C:\\Users\\E26638\\git\\aic-expresso\\target\\jacoco.exec -Xms256m -Xmx1028m -jar C:\Users\E26638\AppData\Local\Temp\surefire10089630030045878403\surefirebooter8801585361488929382.jar C:\Users\E26638\AppData\Local\Temp\surefire10089630030045878403 2019-03-21T21-26-04_829-jvmRun12 surefire10858509118810158083tmp surefire_115439010304069944813tmp"
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1

这是 Surefire Maven 插件配置:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.21.0</version>
        <configuration>
            <skipTests>${skipUnitTests}</skipTests>
            <testFailureIgnore>false</testFailureIgnore>
            <forkCount>1.5C</forkCount>
            <reuseForks>true</reuseForks>
            <parallel>methods</parallel>
            <threadCount>4</threadCount>
            <perCoreThreadCount>true</perCoreThreadCount>
            <reportFormat>plain</reportFormat>
            <trimStackTrace>false</trimStackTrace>
            <redirectTestOutputToFile>true</redirectTestOutputToFile>
        </configuration>
    </plugin>

最佳答案

将项目从 JAVA 8 迁移到 JAVA 11 时遇到同样的问题,将 jacoco-plugin 从 0.8.1 升级到 0.8.4 完成了这项工作。

分析 maven 依赖关系,查看从何处提取 jacoco,然后修复版本应该可以解决问题。

关于java - Surefire Maven 插件 : "Corrupted STDOUT by directly writing to native stream in forked JVM",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55272870/

相关文章:

java - LibGDX + Eclipse |无法加载 .tmx () 文件

java - HashMap.Entry.recordAccess 和 recordRemoval 的目的是什么?

Maven多模块依赖共享

java - 无法将 'cluster' 下的属性绑定(bind)到 com.datastax.driver.core.Cluster

java - 使用 Unitils 针对 Postgres 数据库运行单元测试时出现 NullPointerException

java - 字母频率排序数组

Java derby嵌入式数据库错误: The syntax of the string representation of a date/time value is incorrect

java - 无法在 Maven 依赖管理中找到 jar

gwt - 使用 GIN 注入(inject)的 JUnit 测试,没有 GWTTestCase 和重载 gin 模块?

android - 如何防止特定风格的单元测试被编译成另一种风格?