TestNG concluded more suitable for large-scale testing than JUnit 4

| by Floyd Marinescu Follow 35 Followers on Sep 05, 2006. Estimated reading time: 1 minute |
Andrew Glover compared TestNG and JUnit 4, taking a look at some features that TestNG has over JUnit 4.  Andrew quickly takes the position that TestNG is better for large scale testing, despite JUnit 4's recent addition of annotations and "dramatically relaxed structural rules for test case authoring."   The three killer features that TestNG has over JUnit 4, according to Andrew (summarized here), are:
  1. Flexibility. TestNG doesn't require public init() methods or static test fixtures.
  2. Dependency Testing. In JUnit, for tests that fail, they have an inconvenient consequence: every subsequent dependent test also fails.  TestNG models the notion of dependencies between tests so that  tests dependent on the failed one will be skipped, allowing the rest to proceed. "TestNG's trick of skipping, rather than failing, can really take the pressure off in large test suites."
  3. Re-Running failed tests. TestNG notes which tests failed and allows you to re-run them instead of all of them - handy on large test suites.
  4. Parametric Testing.  In JUnit, if you want to vary the parameter groups to a method under test, you are forced to write a test case for each unique group. You can use FIT to drive tests with tabular data, but TestNG provides a similar feature right out of the box. You can even feed in complex objects with some additional configuration.
The author conludes:
As I said at the beginning of this column, JUnit 4 and TestNG are similar on the surface. But whereas JUnit is designed to hone in on a unit of code, TestNG is meant for high-level testing. Its flexibility is especially useful with large test suites, where one test's failure shouldn't mean having to rerun a suite of thousands. Each framework has its strengths, and there's nothing stopping you from using both in concert.
Recently, build server vendor Zutubi blogged about how the the dependency test feature in TestNG is a good solution for managing tests with occasionally available external dependencies. Back in May, the GlassFish project quality team compared both frameworks and also chose TestNG as the main test suite for Sun's GlassFish testing.  TestNG 5 was released on July 20th.     InfoQ Chief Architect Alexandru Popescu is the co-founder of TestNG 5 along with Cedric Beust.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you