Sachin Francis
Sachin Francis

Reputation: 1121

How to run selective test cases based on nature of data fed by dataprovider in TestNG

Say i have 10 test cases in class, and i have a data provider. Based on the nature of data injected to a test case, i want to decide the set of test cases to be run, out of total 10 tests, probably using IMethodInterceptor.

So i was thinking of setting some data to testContext which i will use in my listener implementing IMethodInterceptor, to decide set of test cases to be run.

Now, the problem which i face here is, where could i set the required test attributes to testContext, so as to read them in listener.

I cant use BeforeTest as it will work fine only for the first data set. and not BeforeClass as it executes after the listener.

So in short how can i run selective test cases based on nature of data fed by dataprovider, using IMethodInterceptor

Upvotes: 1

Views: 239

Answers (2)

MadDogg
MadDogg

Reputation: 21

"I cant use BeforeTest as it will work fine only for the first data set."

Have you tried to use the 'alwaysRun' parameter?

@BeforeTest( alwaysRun=true )

Upvotes: 1

Bob Dalgleish
Bob Dalgleish

Reputation: 8227

Invert the sense of your question: how can I run test cases against only data that appropriate to it?

Create one data provider for each test case. The data provider for a test case is then simply a filter on the master list of test data and provides only interesting test data values to the test case.

Upvotes: 0

Related Questions