0

I have a TestNG Dataprovider tests like below:

Input.csv

id,priority,testData,...
T1,1,someData,...
T1,0,someData,...

Reader

@DataProvider(name="abc")
public Object[][] readData(){
  // Logic to read csv file.
}

Test

@Test(dataprovider="abc")
public void test(){
  // Test code.
}

There are many input files and each test contains a priority. I would like to run the tests which has priority 1 alone.

Without data providers, I'm able to filter the tests using IMethodInterceptor like below.

class interceptor implements IMethodInterceptor {

  @Override
  public List<IMethodInstance> intercept(List<IMethodInstance> instance, 
   ITestContext context){
     for(IMethodInstance method:instance){
        if(method.getMethod().getPriority()==1){
          // Add in new list and return it.
        }
     }
  }
}

Sample Test:

@Test(priority=1)
public void testA(){
 print("A");
}

@Test(priority=2)
public void testB(){
 print("B");
}

Output: A

Since the priorities are dynamic for dataproviders, I'm unable to filter the tests based on the priority.

Other tests should not be executed instead of SKIPPED.

Naveen Kumar
  • 75
  • 1
  • 7

1 Answers1

0

Found it!. TestNG provides IDataProviderInterceptor similar to IMethodInterceptor to handle dataprovider tests.

Sample:

public class Interceptor implements IDataProviderInterceptor {
     
   @Override
   public Iterator<Object[]> intercept(Iterator<Object[]> original, 
                                       IDataProviderMethod dataproviderMethod,
                                       ITestNGMethod method,
                                       ITestContext context) {

      // Typecast original object and filter priority.
   }
}
Naveen Kumar
  • 75
  • 1
  • 7