Does anyone know if there is a way to use a TestNG DataProvider with a test at the same time as using the @Parameter annotation? Our test suites have some constant configuration information that is being passed to the test methods via the @Parameter annotation. We would now like to use a DataProvider to run these tests over a set of data values.
I understand the internal problem of determining the order the resulting parameters would be in but we need to this feature if possible.
Any thoughts?
In an ideal world, I could do something like this:
@Test(dataprovider = "dataLoader")
@Parameters("suiteParam")
public void testMethod(String suiteParam, String fromDataParam) {
...
}
However, TestNG parameters enable us to pass the values only once per execution cycle. To overcome this, we can use DataProvider in TestNG that allows us to pass multiple parameters to a single test in a single execution.
What is the difference between DataProvider and Parameter in TestNG? DataProviders pass the different parameters on a single test in a single execution, whereas parameters pass the parameters just once per execution in TestNG.
Parameterization in TestNG can be achieved in two ways:Using Parameter annotation with TestNG. xml file. Using DataProvider annotation.
Using DataProvider in TestNG, we can easily inject multiple values into the same test case. It comes inbuilt in TestNG and is popularly used in data-driven frameworks. It is an option for the parallel execution of tests in TestNG.
Hey, it may be a bit clunky but why don't you use a @BeforeClass method to store the suiteParam locally on a field of the test class like so.
private String suiteParam;
@BeforeClass
@Parameter("suiteParam")
public void init(String suiteParam) {
this.suiteParam = suiteParam;
}
This way you can use your data providers in the usual way and still have access to your suite param.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With