Quality Testing

Quality is delighting customers

How to use Dependency in TestNG, if test cases from two different classes?

To use Dependency in TestNG, if test cases from two different classes?

Views: 176

Reply to This

Replies to This Discussion

Hi Sandhya,

Can you please provide your exact requirement ?

TestNG is a testing framework widely used in the Software industry by top software testing companies as it continues to provide great support and control over testing frameworks with many advanced features like multiple types of annotations, easy to configure using XML, parallel execution, data-driven tests with parameterization, grouping our tests, priority, and dependency. 

To overcome your problem here we can use groups and dependency feature together since your tests are in different class files.

First, you can create separate groups for both the tests in classes, & after that you can define the dependency on groups.

------------------------------------ Class 1 ------------------------------

package maven.test  
public class Class_A {
@Test (groups = "First")
public void Test_ClassA() {
System.out.println("Test A");

------------------Class 2------------------

package maven.test
public class Class_B {
@Test (groups = "Second",
dependsOnGroups = "First")
public void Test_ClassB() {
System.out.println("Test B");

Run the Class A using TestNG will produce the output:

[RemoteTestNG] detected TestNG version 7.0.0

Test B
Test A

PASSED: Test_ClassB
PASSED: Test_ClassA

Default test
Tests run: 2, Failures: 0, Skips: 0

Default suite
Total tests run: 2, Passes: 2, Failures: 0, Skips: 0

Class_B test method will run before the Class_A test method.

Please do let know in the comments if there's any confusion to the code or any other query related to the test Automation.


TTWT Magazine





© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service