Testing using TestNG

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 annotations

TestNG uses annotations; a few of them are listed in the following table:

Annotation

Import

Description

@Test

org.testng.annotations.Test

It marks the method as a test method

@BeforeMethod

org.testng.annotations.BeforeMethod

The annotated method will be executed before each @test annotated method

@AfterMethod ...

Get Spring: Developing Java Applications for the Enterprise now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.