|
Helping ordinary people create extraordinary websites! |
TestNG Makes Java Unit Testing a BreezeBy Filippo Diotalevi2005-03-22
About the code To illustrate the use of TestNG, I'll write some unit tests for a widely used open source library called Jakarta Common Lang, which contains some useful classes to handle and manipulate strings, numbers, and Java objects. In the Resources section below, you'll find links both to TestNG and the Jakarta Common Lang libraries; you'll need to download both if you plan on following along with this article on your own machine. TestNG is available in two different packages: one that requires JDK 5.0 and another one that is compatible with version 1.4 of the language. They use a slightly different syntax to define tests: The former uses JDK 5.0 annotations, while the latter uses old Javadoc-style annotations. This article uses the JDK 5.0 version, so you'll need to have a basic understanding of annotations before you continue with this article; you can find links to developerWorks resources on the topics in Resources. However, it is important to be aware that JDK 5.0 is required only to compile and run the tests; you can still build your application code with your preferred compiler. In fact, you will test the Jakarta Common Lang library using the same JAR file that you can download from the Jakarta project's Web site. You can find more details about using TestNG with version 1.4 of the Java platform from TestNG's Web site. Finally, click the Code icon at the top or bottom of this article to download j-testng-sample.zip, which contains some examples illustrating how to use TestNG to write unit tests for Jakarta Commons Lang. You will find most of the code presented here, along with some other samples. You won't need this code to read the article, but it can help you understand the concepts explored here in more depth. Tutorial Pages: » Try this testing framework for its advances over JUnit » About the code » TestNG quickstart » Defining test groups » Configuration methods » Exception checking » Wrapping up » Resources First Published on IBM DeveloperWorks |
|