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

TestNG Depedency Test – Multiple Test Method Dependency

DZone's Guide to

TestNG Depedency Test – Multiple Test Method Dependency

· Java Zone
Free Resource

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. 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.

The dependency on multiple test methods is configured for a test by providing comma separated dependent test method names to the attribute dependsOnMethods while using the Test annotation.

The following example shows a test class where process() test method depends on multiple test methods start() and initi() of the same class.

Code

?
package com.skilledmonster.example;
import org.testng.annotations.Test;
/**
* Example to demonstrate TestNG multiple dependency method execution
*
* @author Jagadeesh Motamarri
* @version 1.0
*/
public class MultipleDependencyTest {
@Test
public void start() {
System.out.println("Starting the server");
}
@Test(dependsOnMethods = { "start" })
public void init() {
System.out.println("Initializing the data for processing!");
}
@Test(dependsOnMethods = { "start", "init" })
public void process() {
System.out.println("Processing the data!");
}
@Test(dependsOnMethods = { "process" })
public void stop() {
System.out.println("Stopping the server");
}
}

Output


TestNG Depedency Test - Multiple Test Method Dependency - Output

As seen in the above console output, process() method executed after start() and init() methods are executed and like wise stop() method is executed after process()  method is executed.

Download

[GitHub]

Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

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

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}