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

TestNG Dependency Test: Single Test Method Dependency

DZone's Guide to

TestNG Dependency Test: Single Test Method Dependency

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

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 a test method is configured for a test by providing the dependent test method name to the attributedependsOnMethods while using the Test annotation.

The following example shows a test class where one test method depends on another test method of the same class.

Code?

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

Output

As seen in the above output, process() method is not executed before start() method and stop() method is not being executed before process() method.


Download

[GitHub] https://github.com/skilledmonster/TestNG_Examples/tree/master/Single_Dependency_Test_Example 

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

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 }}