|
Helping ordinary people create extraordinary websites! |
TestNG Makes Java Unit Testing a BreezeBy Filippo Diotalevi2005-03-22
Exception checking With TestNG, you can check the occurrence of an exception very simply and easily. It is obviously possible to do this with JUnit as well, but using the @ExpectedExceptions annotation with TestNG makes the code of the test surprisingly easy and straightforward to write, as you can see in the example presented in Listing 6. The @ExpectedExceptions annotation specifies that the raising of a NumberFormatException is tolerated by the framework and therefore should not be considered a failure. To see if an exception is raised in a certain line of code, you can add an assert false statement just after that line. This means that you will pass the test only if that particular type of exception is raised in the designated line. Listing 6. Exception checking with TestNG public class NumberUtilsTest 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 |
|