3

I have a set of tests that take a long time to execute in total. I'd like to shorten some of my test runs by changing all data providers to return only one set of parameters.

I've read through the TestNG documentation and javadoc, but there doesn't appear to be anything like an IDataProviderListener. IMethodInterceptor might work for tests that don't have dependencies set, but that would be an incomplete solution.

I'm also aware that there may be other ways to reduce test time, but I have limited options as my test fixture is physical, slow, and expensive (so parallelization is not available.)

As a concrete example, lets say I have 3 tests: TestA, TestB, TestC, and Test B and C use unique dataproviders. TestB's dataprovider normally returns 5 sets of parameters resulting in 10 executions of TestB. Similar for TestC, but it's dataprovider normally returns 1 parameter set resulting in a single run of TestC. The normal execution would be:

  • TestA
  • TestB
  • TestB
  • TestB
  • TestB
  • TestB
  • TestC

What I want is a way to get the following without modifying the dataprovider or test code source:

  • TestA
  • TestB
  • TestC
Erik Shreve
  • 174
  • 7
  • Eric, AFAIK there's nothing out there that can do this for you in TestNG. So I logged an enhancement ticket on the TestNG issues for this. Refer and track it [here](https://github.com/cbeust/testng/issues/2111) – Krishnan Mahadevan Jul 12 '19 at 04:31

1 Answers1

1

In QAF which is extension to TestNG, implemented such use case outside TestNG by providing data provider intercepter. It also provides capability to filter test-data. Below is the example of QAFDataProviderIntercepter implementation:

public class MyDataProviderIntercepter implements QAFDataProviderIntercepter{

 public void beforeFech(TestNGScenario scenario, ITestContext context){

 }
 public void List<Object[]> intercept(TestNGScenario scenario, ITestContext context, List<Object[]> testdata){

  //provide logic here
 }

}

You need to register this class as qaf listener.

user861594
  • 5,733
  • 3
  • 29
  • 45