Wednesday, April 13, 2005


I've been playing with some new Unit Testing technology called TestNG. If you've used JUnit or any of the XUnit clones, you probably understand the power that those tools provide.

But as I've found, JUnit is great for testing classes...but what happens when you're trying to do tests on dynamic input? What happens when you're trying to see if the input stream is valid based upon different contractual based rules?

That's where TestNG can be quite handy. I've tried writing these tests in JUnit and end up being quite thankful the tool is open source. Why? Because I end up hacking the JUnit code to death in order to make it dance.

Essentally in order to write my varied input stream test, I had to override many of the JUnit methods. In TestNG, I override none. I author a Factory annotated method to create instances of TestClasses, and TestNG will run each instance. In JUnit, I parameterization is quite difficult, requiring several add-ons. TestNG has this functionality built right in.

TestNG is young. It's still changing, but the development team is very receptive. I had an issue with execution order annotations (@beforeTestMethod for example), where they did not execute as expected when passed in through a @Factory. Within a few days of understanding the issue, it was resolved with a patch.

I highly reccomend checking TestNG out if JUnit has ever frustrated you when you want to do more than just unit test. Systems Integrators and product implementations groups would definately see the benefit from this tool as they are much more likely to have to run more flexible tests.

No comments: