TestNG concluded more suitable for large-scale testing than JUnit 4
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:
Discuss
- Flexibility. TestNG doesn't require public init() methods or static test fixtures.
- 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."
- 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.
- 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.
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.
Community comments
Educational Content
Intro to CLP with core.logic
Ryan Senior Jun 18, 2013
Spock: A Highly Logical Way To Test
Howard Lewis Ship Jun 18, 2013
Java Garbage Collection Distilled
Martin Thompson Jun 17, 2013
C++11 The Future is Here
Bjarne Stroustrup Jun 16, 2013
The Big Data Revolution
Claudia Perlich Jun 16, 2013
Sponsored Links




Hello stranger!
You need to Register an InfoQ account 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