|
Helping ordinary people create extraordinary websites! |
TestNG Makes Java Unit Testing a BreezeBy Filippo Diotalevi2005-03-22
Defining test groups Another interesting feature of TestNG is its ability to define groups of tests. Every test method can be associated with one or more groups; once you've defined these groups, you can choose to run only certain groups of tests. To add a test to a group of tests, simply specify the group as a parameter of the @Test annotation, using the following syntax: @Test(groups = {"tests.string"}) In this particular case, you declare that the annotated method belongs to the tests.string group. Because the parameter groups is an array, it is possible to specify multiple groups, separating their names with commas. For example, in the sample application, you can create different tests for Strings, numbers, and booleans, and then run them selectively, configuring TestNG as illustrated in Listing 4. Listing 4. Configuration file with different groups <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" > Obviously, when you run different groups of tests, the HTML report can show all the tests in a single list, as well as in separate lists for each group, making it possible to immediately understand the source of any problem. 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 |
|