Book Image


Book Image


Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
About the Author
About the Reviewers

Unit testing with TestNG 6

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.

Getting ready

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;

How to do it…

Follow these steps to test a method with TestNG 6:

  1. Add the testng Maven dependency in pom.xml:

  2. In Eclipse, install the TestNG plugin. In the Help menu, select Install New Software.... In the Work with: field, enter