TestNG

Java Add comments

After spending some time playing with the latest version of TestNG I’ve decided to begin the switch from JUnit. TestNG is an evolutionary step forward in unit testing for Java. For me a big advantage is that it makes it much easier to group my tests. Right now I use separate test directories which, although functional, is at times a pain in the ass, TestNG allows me to group using annotations. Setup is also a hell of a lot easier. I can choose if a method executes before each test or just once for the test class which makes expensive operations such as managing database connections easier to manage. The other bonus is test dependencies. I know, I know, there is the whole “tests should be independent argument”, but what is the point of testing operations on a connection if the test to create that connection fails?

To be honest the reason I’ve waited until now to switch has been the lack of IDE support for TestNG. That changed a couple of weeks ago when Cédric announced the TestNG Eclipse plug-in making it trivial to use TestNG directly from eclipse. I’m not changing everything over night (I have hundreds of test classes). New test classes are now written in TestNG and if I need to go back and extend or resolve an issue in a current test class I update it to TestNG. My old tests are run using TestNGs JUnit compatibility mode so that I get a single report for all my tests.

TestNG comes with a lot of documentation. For a shorter introduction I recommend you read TestNG makes Java unit testing a breeze.

Leave a Reply

Couldn't find your convert utility. Check that you have ImageMagick installed.