Over a million developers have joined DZone.

TestNG Dependency Test – Inheited Test Dependency

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

Dependency is a feature in TestNG that allows a test method to depend on a single or a group of test methods. This will help in executing a set of tests to be executed before a test method.

Dependency on test methods can only be mentioned for test methods that belong to the same class or any of the inherited base classes.

The following example shows a test class where dependent methods are part of the inherited base class.


Base Test Class – BaseTest

package com.skilledmonster.example;
import org.testng.annotations.Test;
* Example to demonstrate TestNG inherited dependency method execution
* @author Jagadeesh Motamarri
* @version 1.0
public class BaseTest {
public void start() {
System.out.println("Starting the server");

Inherited Test Class – InheritedDependencyTest extends BaseTest

* Example to demonstrate TestNG inherited dependency method execution
* @author Jagadeesh Motamarri
* @version 1.0
publicclassInheritedDependencyTest extendsBaseTest {
@Test(dependsOnMethods = { "start"})
publicvoidprocess() {
System.out.println("Processing the data!");
@Test(dependsOnMethods = { "process"})
publicvoidstop() {
System.out.println("Stopping the server");



As seen in the above console output, start() method which is part of the BaseTest class is executud first before executing process() method.

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.


Published at DZone with permission of Jagadeesh Motamarri, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}