1

Problem setting I want to investigate some problems we have regarding when objects used in tests are finalized. Therefor I would like to know in greater detail how surefire runs JUnit tests.

It seems that some of these still exist while other tests are run, probably because of

  • garbage collection
  • surefires timeout for forked JVMs. As this can happen basically at any point in time /at random, I want to understand the interaction between Surefire and JUnit 4.11.

My Question What is the execution order/path to executing a test method when I invoke mvn test? How are tests run with forkCount={0,1}? How does surefire create a fork of the JVM and where in surefire's source code does this happen? When is the fork killed and does it run finalizers?

The surefire version used is 2.16.

I found these classes and followed a lot more, but I got sort of lost in the haywire: ForkStarter It seems that surefire manages communication via ForkClient, however I cannot find a the point where a new JVM process is started/ended and the surefire page does not give me a precise clue either.

Also I found this document, giving some pointers for classes to start: https://github.com/apache/maven-surefire/blob/8881fabb9625522a4790ef8c96179233a51e7385/maven-surefire-plugin/src/site/apt/developing.apt.vm

Tunaki
  • 132,869
  • 46
  • 340
  • 423
user3001
  • 3,437
  • 5
  • 28
  • 54
  • Which version of maven-surefire-plugin do you use? – khmarbaise Oct 27 '15 at 11:22
  • don't use finalizers. it's not reliable and you will waste time for issues like this one. see: http://stackoverflow.com/a/2506525/1100135 – piotrek Oct 27 '15 at 14:16
  • I know that question, still there are some valid cases. For instance we use this to report if resources weren't freed properly and explicitly in unit tests, as they should have (e.g. using `@After(Class)`). Also finalization is not the scope of my question, I'm more interested into the general lifecycle and its inner details :) – user3001 Oct 27 '15 at 16:20

0 Answers0