Search code examples
javaperformancejunitjunit4junit3

Is there a performance difference between JUnit3 and JUnit4?


I would like to know if there is a difference in running a JUnit3-Test or a JUnit4-Test. Even if it is just 5-10% improvment on the total runtime, in a big project with nightly builds this could matter.

Subquestins are:

  • Does the TestRunner improved on the update to Junit4?
  • Or does it take longer to resolve @annotation in JUnit4 style?
  • Benefits a JUnit3 written test of a JUnit4 execution?

If possible please answer with references.


Solution

  • I suspect that given what JUnit does (mainly provide a framework for people to write tests), that the differences, if any, are negligible. As with most performance issues and queries, you should probably perform measurements yourself for your particular scenario.

    Any test performance issues I've seen in the past relate to how the developers write the actual tests, and whether they handle issues like:

    1. set up pre-conditions in advance for a set of tests, rather than perform set up for each individual test (e.g. see @BeforeClass)
    2. perform accesses to remote resources (servers, databases etc.) in situations where mocking may be preferable
    3. write tests around threading issues, with Thread.sleep() interspersed to allow for scheduling issues

    If you're really concerned with test framework speed, then perhaps you should also evaluate TestNG ?