Saturday, October 01, 2005

Unit Testing in Java with TestNG

It is now about three years that I started to use JUnit and its family members like DbUnit, XmlUnit etc. For my work I have written a DbUnit wrapper that eases the DbUnit usage. I have used XmlUnit for a while to test XML files. I have also used MockObjects as for example EasyMock, JMock, and others.

Recently I came accross TestNG and started to read about it. Tonight I finally decided to have a close look at TestNG and actually use it. What attracts me first is the grouping of tests and the easy way to include or exclude tests. Eclipse has this nice feature where you can right click on a single test and execute it. I make very often usage of this feature to avoid executing other time intensive tests.

What TestNG provides is so much more advanced. Just group tests with annotations and in your TestNG suite xml file define which ones to include, and which ones to exclude.

Another thing that helps me to get started with TestNG is the fact that there is a TestNG Eclipse plugin which allows to run TestNG test cases in the same way as I am used doing it with JUnit tests.

Maven
TestNG provides also a Maven plugin. It took me a while to figure out how to get it. On the TestNG site I could only locate a page that explains the Maven TestNG plugin, but not how to get it. I finally found the information in the TestNg Group available on Google groups.

What you need to do is the following (copied from the News Group posting):
issue the plugin:download command and answer the questions as follows:
  • artifactId is maven-testng-plugin,
  • groupId is testng,
  • and version is 1.1
You'll need to add http://www.vanwardtechnologies.com/repository to your maven.repo.remote list.

No comments: