quality@glassfish.java.net

TestNG vs JUnit4

From: Geoffrey Halliwell <Geoffrey.Halliwell_at_Sun.COM>
Date: Mon, 24 Apr 2006 12:55:26 -0700

Interesting commentary from the TestNG User group...

----------------------------------------------------------------------

I can't believe people are keep using JUnit when TestNG is so much superior!

I've just spent a couple of minutes to see what's new in JUnit 4 and I'm
amazed of how little has changed comparing to the time passed since the
last version has been released.

Yes, you no longer need to extend TestCase and confined to prefix your
methods with "test" or call them setUp and tearDown, but other than
utilizing annotations and few other improvements which suspiciously
remind TestNG, I can't see why anyone would prefer JUnit over TestNG.
Every "new"feature in JUnit 4 has been existed in TestNG for months (at
best) and the fact that TestNG can be reduced to JUnit (i.e. run JUnit
tests) only shows how powerful TestNG is. As a matter of a fact, I think
the only advantage JUnit has over TestNG is its market share and media
hype. With the right marketing I have no doubt TestNG will became "the
de facto standard framework for testing Java code".

I could probably write a whole paper explaining why TestNG is at least
an order of magnitude better than JUnit but just to name a few points:

* Groups - In my opinion, the most important feature in TestNG. I can't
  stress enough how powerful this feature is, especially when combined
  with BeanShell.
* Configuration wrappers (methods) at every existing level (not just
  method/class level). The independence of tests is a good idea in
  theory but is often not practical in large projects or when (slow)
  hardware is involved.
* Execution model - no more hardcoded-error-prone-impossible-to-maintain
  suites!
* Dependencies among methods and groups
* Data providers & Parameters
* Thread pools
* Distributed testing

I could go on but the last point I'd like to mention, which is the most
important, is the amazing support from Cedric and Alexandru. I can't
remember how many times I missed a feature or found a bug and had a
new/fixed TestNG version in a day or two (sometimes hours!).