O'Reilly logo

Test-Driven Java Development - Second Edition by Viktor Farcic, Alex Garcia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

TestNG

In TestNG (http://testng.org/doc/index.html), tests are organized in classes, just as in the case of JUnit.

The following Gradle configuration (build.gradle) is required in order to run TestNG tests:

dependencies { 
   testCompile group: 'org.testng', name: 'testng', version: '6.8.21' 
} 
 
test.useTestNG() { 
// Optionally you can filter which tests are executed using //    exclude/include filters 
// excludeGroups 'complex' 
} 

Unlike JUnit, TestNG requires additional Gradle configuration that tells it to use TestNG to run tests.

The following test class is written with TestNG and is a reflection of what we did earlier with JUnit. Repeated imports and other boring parts are omitted with the intention of focusing on the relevant parts:

@BeforeClass ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required