TestNG Makes Java Unit Testing a Breeze
By Filippo Diotalevi2005-03-22
Try this testing framework for its advances over JUnit
In the construction phase of every modern software package, the practice of testing plays a central role. Gone are the days of coding first and testing whenever you have time (or not at all), as most developers now recognize the need to adopt a software methodology in which coding and testing are intermingled and contemporaneous, so as to catch bugs early and identify major risks at the very beginning of the development process.
More than any other testing framework, JUnit has driven developers to understand the usefulness of tests, especially of unit tests. Leveraging a rather simple, pragmatic, and strict architecture, JUnit has been able to "infect" great number of developers. (See Resources for more information on being "test infected.") JUnit users have learned some fundamental rules of unit testing:
• Every single piece of code must be tested.
• Whenever possible, code must be tested in isolation (using, for example, techniques like mock objects).
• Software must be easy testable -- that is, written with tests in mind.
However, as developers' confidence with tests has increased, JUnit's simplicity and strictness has divided them into two opposed factions. On the one hand, there are those who firmly believe that JUnit's simplicity is necessary to continuously remind programmers that software must be simple too (this is known as the KISS principle, for keep it simple, stupid); on the other hand, there are those who, seeing JUnit more as simplistic than simple, want new advanced features, more flexibility, and more power from their testing framework. Some peculiar features of JUnit come in for particular criticism from the latter group:
• The need to extend a TestCase class, because the Java language has single inheritance, is very limiting.
• It is impossible to pass parameters to JUnit's test method as well as to setUp() and tearDown() methods.
• The execution model is a bit strange: The test class is reinstantiated every time a test method is executed.
• The management of different suites of tests in complex projects can be very tricky.
| The creator of TestNG
The creator of TestNG is Cedric Beust, a well-known name in the field of Java programming, a member of the EJB 3 expert group, and creator of other popular open source projects like EJBGen and Doclipse. TestNG is distributed under the terms of Apache Software License and can be downloaded from its Web site (see Resources for a link to this and to Cedric's site). |
Tutorial pages:
|
First Published on IBM DeveloperWorks
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "TestNG Makes Java Unit Testing a Breeze"
You must be logged in to post a comment.
Link to This Tutorial Page!

