testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.98k stars 1.02k forks source link

Add dataProviderSubset property to @Test #138

Closed nithril closed 12 years ago

nithril commented 12 years ago

It could be nice to restreint test data from a DataProvider to a subset of the data.

eg. : @Test(dataProvider = "dp" , dataProviderSubset = {0,2})

Use case A test go in error for the 4th row of the data provider. Instead of creating a new data provider, dev can use this property to isolate the error

cbeust commented 12 years ago

Hi Nicolas,

Interesting idea. Not sure if you already knew this but if you run a test with a dataprovider say with three sets of parameters and only the second set causes a failure, TestNG creates a testng-failed.xml file that will do exactly that (it will only invoke the test method with the second set of parameters).

So there is already some partial support for your idea, just not at the annotation level.

cbeust commented 12 years ago

Thinking a bit more about this, I don't think it's necessary to add an attribute to @DataProvider since you can always modify your data provider to only return the set of parameters you need, so I'll close this issue unless you object...

nithril commented 12 years ago

Hi Cedric,

I know testng-failed.xml. I used it seldom through Intellij.

I agree you can modify the DataProvider to return only the datas which failed the test

Matter of developpment process (say TDD) I think it is less errror prone to not modify the dataprovider but to create a new test A' which used a subset of the same dataprovider.

dev can launch the two test without any code or dataprovider modification. As soon as A' passed, dev can delete A'. DataProvider and A remains unmodified.

To be honest I met only the case in 6 month.

cbeust commented 12 years ago

I just implemented this functionality in the beta: @DataProvider(indices = { 1,2,4 }).

Please try it and report back: http://testng.org/beta

nithril commented 12 years ago

Sorry to be late. I have test today with a real use case and it's works.

Thanks Cedric!