Mutant World

Wednesday, May 31, 2006

TestNG and Maven

I've been working with JDK 5, and some time ago I decided to try TestNG as test framework, leaving back JUnit.

Since then, I got addicted to TestNG, and if possible, will never go back to JUnit, as really TestNG is leaps beyond JUnit.

Now I am working also on a JDK 1.4 application that I build using Maven.
I've been really impressed by the fact that Maven supports TestNG out of the box, even in JDK 1.4 (using Javadoc annotations). Well, time to convert all tests from JUnit to TestNG, and it's very easy:

Before:

public class MyTest extends junit.framework.TestCase
{
public void testSomething() throws Exception
{
assertTrue(true);
}
}


After:

public class MyTest
{
/**
* @testng.test
*/
public void testSomething() throws Exception
{
assert true;
}
}


Plus, you get all cool TestNG features:

  • configurable advice methods (that run before/after the suite, the groups, the class, the test)

  • configurable dependencies among tests

  • configurable number of runs

  • configurable parameters to pass to the test

  • ...and much more