TestNG, first released in 2004, is the second most popular Java unit testing framework. With most of JUnit features, it also offers parameterized testing (executing a test method with different sets of data) and convenient features for integration testing.
In this recipe, we will write a parameterized test to test the same method as in the previous recipe.
In this recipe, we'll test this simple method (located in the NumberUtil
class), which adds two integers:
public static int add(int a, int b) { return a + b; }
Follow these steps to test a method with TestNG 6:
Add the
testng
Maven dependency inpom.xml
:<dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.1.1</version> <scope>test</scope> </dependency>
In Eclipse, install the TestNG plugin. In the Help menu, select Install New Software.... In the Work with: field, enter
http://beust.com/eclipse...