Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

TestNG Dependency Test – Inheited Test Dependency

DZone's Guide to

TestNG Dependency Test – Inheited Test Dependency

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

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.

Code

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 {
@Test
public void start() {
System.out.println("Starting the server");
} 
}
?

Inherited Test Class – InheritedDependencyTest extends BaseTest

?
packagecom.skilledmonster.example;
importorg.testng.annotations.Test;
/**
* 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");
}
}

Output

testng_dependency_inheited

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

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.

Topics:

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

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

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

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}