"Forked Java VM exited abnormally" error from junit tests

Viewed 54482

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:

Error Message

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

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.

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

17 Answers

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.

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

I use ant 1.7.1, so no hope with upgrading 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.

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

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.

I added TestNG library to the Test Libraries and it fixed the issue.

In my case, the classpath that my tests were running on exceeded the maximum length of what was allowed by the Operating System for an environment variable (aka the Linux Classpath too long issue).

The solution was to create a pathing jar. Simplified steps:

  1. Use jar (or your IDE) to make a jar of your project, we'll call it MyProject.jar

  2. Make a file called Manifest.txt with the text

Class-Path: MyProject.jar

  1. Run the jar command line this

jar cfm PathingJar.jar manifest.txt MyRootPackage/*.class

Then, in your build tool, run your test directive against the pathing jar itself (don't mix-in other classes or jars). Then I was able to get my tests to run without that exception.

I faced similar issue while running the tests on Jenkins, same tests were passing locally.

I was able resolve the issue by setting log level to WARN

Related