TestNG (Next Generation) is another testing framework that is similar to the JUnit 4 framework, but it has new functionalities such as grouping concept, and dependency testing. These have made testing easier and more powerful. It is designed to cover all the categories of tests, such as the unit test, the functional test, the integration test, and so on. TestNG also supports multi-threaded testing.
TestNG uses annotations; a few of them are listed in the following table:
Refer to the link http://testng.org/doc/download.html to set up TestNG for your IDEs. Add TestNG JAR to your
CLASSPATH
to compile and run the test cases created for TestNG, as shown here:
package org.packt.Spring.chapter9.SpringTesting.Calculator; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class SimpleCalculatorTestNGTests { private SimpleCalculator simpleCalculator; @BeforeMethod public void beforeMethod() { simpleCalculator = new SimpleCalculatorImpl(); } @Test public void verifyAdd() { long sum = simpleCalculator.add(3, 7); Assert.assertEquals(10, sum); } }
You will see a progressive green bar if your test case passes: