junit 测试中出现“分叉 Java VM 异常退出”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1846329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 23:16:21  来源:igfitidea点击:

"Forked Java VM exited abnormally" error from junit tests

javaantjunithudson

提问by Alb

I have a java junit test that passes when run alone on a development machine. We also have a hudson job which runs all the tests, invoked via ant, on a Mac OS X 10.4 node with Java 1.5. The test was passing in the hudson build until recently but now (with no related code changes) one test fails everytime with the following error:

我有一个 java junit 测试,它在开发机器上单独运行时通过。我们还有一个 hudson 作业,它在带有 Java 1.5 的 Mac OS X 10.4 节点上运行通过 ant 调用的所有测试。直到最近,该测试才通过 hudson 构建,但现在(没有相关代码更改)每次测试都失败并出现以下错误:

Error Message

错误信息

Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.

Forked Java VM 异常退出。请注意,报告中的时间并不反映 VM 退出之前的时间。

Stacktrace

堆栈跟踪

junit.framework.AssertionFailedError: Forked Java VM exited abnormally. Please note the time in the report does not reflect the time until the VM exit.

junit.framework.AssertionFailedError: Forked Java VM 异常退出。请注意,报告中的时间并不反映 VM 退出之前的时间。

googling shows many others seem to have run into the same problem but there I couldn't find any answer.

谷歌搜索显示许多其他人似乎遇到了同样的问题,但我找不到任何答案。

采纳答案by Prashanth

I faced a similar issue. I ran the junit tests as an ant task. I added the showoutput="yes"ant junit property and ran the ant junit task. It then showed the exception stack trace that caused the forked jvm to exit.

我遇到了类似的问题。我将 junit 测试作为 ant 任务运行。我添加了showoutput="yes"ant junit 属性并运行了 ant junit 任务。然后它显示了导致分叉 jvm 退出的异常堆栈跟踪。

回答by Francis Upton IV

I had this problem and it turns out that the process was actually calling System.exit(). However there was also a bug in Ant where this was showing up sometimes. I think Ant 1.7.1 has the bug fixed. So make sure you are running that version.

我遇到了这个问题,结果发现该进程实际上是在调用 System.exit()。然而,在 Ant 中也有一个错误,有时会出现这种情况。我认为 Ant 1.7.1 修复了错误。因此,请确保您正在运行该版本。

回答by Brian Agnew

Is the VM crashing ? Can you find a dump file (called hs_err_pid*.log) ? If that's the case, the dump file will give you clues to why this is crashing out.

虚拟机崩溃了吗?你能找到一个转储文件(称为hs_err_pid*.log)吗?如果是这种情况,转储文件将为您提供有关崩溃原因的线索。

回答by Sharebear

I believe I saw this error once when I ended up with multiple versions of junit on my classpath. Might be worth checking out.

我相信当我最终在我的类路径上有多个版本的 junit 时,我曾经看到过这个错误。可能值得一试。

回答by triggerNZ

I had the exact same thing a while back. The problem is that System.exit() is being called somewhere. It can be difficult to find though, as the call could come from either your code or one of the libraries you use.

前段时间我也有同样的事情。问题是 System.exit() 在某处被调用。但是可能很难找到,因为调用可能来自您的代码或您使用的库之一。

回答by Tristan

For me, it was an "java.lang.OutOfMemoryError" in the forked VM (junit task with fork="yes") which made this message appear in the main VM.

对我来说,它是分叉 VM(带有 fork="yes" 的junit 任务)中的“java.lang.OutOfMemoryError”导致此消息出现在主VM 中。

The OutOfMemory was visible in the ant log (well, is visible since it's still present).

OutOfMemory 在 ant 日志中是可见的(嗯,是可见的,因为它仍然存在)。

I use ant 1.7.1, so no hope with upgrading ant.

我使用 ant 1.7.1,所以升级 ant 没有希望。

After putting the same VM parameters in "Run>External tools>External tools>JRE" than in Eclipse.ini (-Xms40m -Xmx512m -XX:MaxPermSize=256M) the problem is solved.

在“运行>外部工具>外部工具>JRE”中放入与 Eclipse.ini (-Xms40m -Xmx512m -XX:MaxPermSize=256M) 中相同的 VM 参数后,问题就解决了。

I keep fork to "no" to be sure ant use the parameters.

我将 fork 设置为“no”以确保 ant 使用参数。

回答by ChikoFerrara

I solved my issue by setting the following environment variable:

我通过设置以下环境变量解决了我的问题:

Variable: _JAVA_OPTIONS Value: -Xms128m -Xmx512m

变量:_JAVA_OPTIONS 值:-Xms128m -Xmx512m

回答by KlasE

For us, it was actually that we by accident (used a newer version of eclipse) started to use Ant 1.7.x instead of our old ant version which was compatible with our Weblogic 8.1/JDK 1.4.x environment. We fixed this by changing back the Ant Home in Eclipse->Windows->Preferences->Ant->Runtime to our old version of Ant.

对我们来说,实际上是我们偶然(使用了较新版本的 eclipse)开始使用 Ant 1.7.x 而不是与我们的 Weblogic 8.1/JDK 1.4.x 环境兼容的旧 ant 版本。我们通过将 Eclipse->Windows->Preferences->Ant->Runtime 中的 Ant Home 改回我们的旧版 Ant 来解决此问题。

Regards Klas

问候克拉斯

回答by ankit jain

I have multiple junit jars in my classpath. one is of ant and another is from WAS. As I removed that the error went away... Ant version that I am using 1.8

我的类路径中有多个 junit jar。一个来自蚂蚁,另一个来自 WAS。当我删除错误消失了...我使用的 Ant 版本 1.8

回答by Alex C

This can occur when an uncaught RuntimeException is thrown. Unfortunately, the junit ant task doesn't output the exception so there isn't an easy way to determine the root cause. You can work around this by running the test case from the command line where the exception will be shown.

当抛出未捕获的 RuntimeException 时,可能会发生这种情况。不幸的是,junit ant 任务不会输出异常,因此没有一种简单的方法可以确定根本原因。您可以通过从将显示异常的命令行运行测试用例来解决此问题。

java <vm-args> org.junit.runner.JUnitCore <test-class-name>

In my case, an IllegalArgumentException was being thrown.

就我而言,抛出了 IllegalArgumentException。

回答by user1164061

I faced the same issue. The problem was with byte code generation with mocking the Config class; We changed the import to

我遇到了同样的问题。问题在于通过模拟 Config 类生成字节码;我们将导入更改为

import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

and it worked.

它奏效了。