Little Bobby Tables
Little Bobby Tables

Reputation: 5351

TestNG data provider parallel parameter not in code annotation

I have an TestNG test method that is ran with multiple parameters using a data provider:

@DataProvider()
public Object[][] scenarios() {...}

@Test(dataProvider = "scenarios")
public void check(...) {...}

Sometimes I want to run the check tests in parallel and sometimes not. I can control that by setting the code annotation to @DataProvider(parallel = true) or @DataProvider(parallel = false), but I want to do that as a run-time parameter, not as a setting in the code.

How can I set if a data provider spawns multiple threads either as a command-line argument or an attribute in the TestNG suite XML file?

Upvotes: 1

Views: 769

Answers (2)

juherr
juherr

Reputation: 5740

Annotation Transformers are what you look for. With them, you will be able to modify the value of parallel depending on your own business rule (for example: an env var).

Upvotes: 2

RocketRaccoon
RocketRaccoon

Reputation: 2599

You may try to pass ITestContext to data provider and get e.g. groups from test ('singleTest' or 'parallelTest'). In data provider return only one object for singleTest group, it should be enough.

Upvotes: 0

Related Questions