views:

576

answers:

1

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) {
...
}
+1  A: 

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.

mR_fr0g