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

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

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.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. 

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}