2

I have a DataProvider which reads a CSV file like below

john|26|mba
claire|33|bbl
knight|29|mpa

Now I have three classes which has one @Test each

Classes Names are

NameReader.java
ProcessStudent.java
ValidateDatabase.java

My NameReader.java has one @Test method which gets the input from the aforementioned data provider. So in this case if I execute just the NameReader.java it will run 3 times since there are three rows

But the problem is I want NameReader.Java to accept 1st row from the data provider and then run ProcessStudent.java and then run ValidateDatabase.java. This flow should happen for remaining two rows from the DataProvider as well.

But if I specify my testng.xml as below

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test thread-count="1" name="Test" preserve-order="true">
    <classes>
      <class name="com.java.testng.NameReader"/>
      <class name="com.java.testng.ProcessStudent"/>
      <class name="com.java.testng.ValidateDatabase"/>
    </classes>
  </test>
</suite> 

It runs the @Test inside NameReader.java 3 times first and then moves on to the @Test inside ProcessStudent.java and then to the @Test inside ValidateDatabase.java.

Please remember I don't need to use the aforementioned DataProvider in either ProcessStudent.java or ValidateDatabase.java

How can I achieve what I need?

Damien-Amen
  • 7,232
  • 12
  • 46
  • 75

1 Answers1

0

Call ProcessStudent and ValidateDatabase test methods from NameReader test method. Had to declare ProcessStudent and ValidateDatabase test methods as static methods.

public class NameReader {

@Test(dataProvider = "getData")
public void testNameReader(String str1, String str2) {

    System.out.println("data set = "+str1+"  "+str2);
    System.out.println("NameReader ends");

    ProcessStudent.testClassB();
    ValidateDatabase.testClassC();
}

@DataProvider
public Object[][] getData(){
//data set here
 }
A-K
  • 161
  • 3
  • 13