Book Image

SPRING COOKBOOK

Book Image

SPRING COOKBOOK

Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.1.1</version>
      <scope>test</scope>
    </dependency>
  2. In Eclipse, install the TestNG plugin. In the Help menu, select Install New Software.... In the Work with: field, enter http://beust.com/eclipse...