11

I sometimes get this error when I run the JUnit tests.

I'm not exactly asking what the error is. I just want to know what it means when the java VM forks?

Dezrik
  • 169
  • 1
  • 8
  • Forking in the general sense, executing a jUnit task in another JVM. – CoolBeans Dec 15 '11 at 03:16
  • 5
    It means you forked up bad... – Paul Dec 15 '11 at 03:16
  • It would be helpful to know the exact error message. Is this similar to your problem? http://stackoverflow.com/questions/1846329/forked-java-vm-exited-abnormally-error-from-junit-tests – Paul Dec 15 '11 at 03:18
  • e.g. in ant, you can specify whether you want to run junits in the same vm or you want to fork a new one (to manage heap exclusively for junits). I guess your build/ test tool has something similar. – aishwarya Dec 15 '11 at 03:18
  • Haha, thank you for the answers. @Paul, yes it's similar but I think mine is DLL related. It's still difficult to find out the problem. Still my question is answered, and that's one less problem for me. – Dezrik Dec 19 '11 at 08:35

2 Answers2

29

A "forked VM" is not an error (although the error you get may be related to it).

Some tools that are involved in various aspects of compilation and testing (e.g. Maven) are written in Java and use the JVM to run themselves.

If you run unit tests for your application without forking the VM, Maven will run those tests within the same VM as Maven is running. Therefore, it may be affected by certain VM-wide settings (e.g. some system properties).

To avoid side-effects due to Maven, it's possible to run the tests in a forked VM, that is, in a completely separate VM running as a different process in the OS.

(This can apply to other tools, Maven is just an example.)

Crashing a forked VM at least allows you to come back to the other Java application that started and orchestrated these unit tests. If you were running these tests within the same VM, you would also crash the application that launched your tests (and thus get very little information in return).

Bruno
  • 119,590
  • 31
  • 270
  • 376
2

A 'fork' is the terminology used in Linux to denote executing another process (loosely). In this case, a forked Java VM is a child process used to isolate your unit tests by class or method, ensuring that no state pollution occurs between multiple tests.

The JUnit ant task supports multiple forking modes as can be seen here.

I have seen errors that state that a forked VM has died when using JUnit. This means that your test is crashing and that your JUnit runner (usually ant) cannot get any of the output.

You should try to resolve the cause of the crash.