0

I have a TestNG Dataprovider with full of test data. I'm parsing an Excel sheet, so dataprovider has eg. 15 test data list.

I do not want to run my tests with all the 15 test data set, only one. Is it possible to filter the dataset and run the tests with that dataset only? For instance, let's run the test with id1 row. It is just an example, I'm going to store my data as a test object list.

@DataProvider(name = "testCaseSet1")
    public static Object[][] getTestData() {
        return new Object[][] {
                {"id1","testuser1", "test"},
                {"id2","testuser2", "test2"}
        };
    }
arena
  • 233
  • 3
  • 15

1 Answers1

1

One way would be to use:

@DataProvider(name = "testCaseSet1", indices = {0})
t6nn
  • 81
  • 3
  • can you clarify this? indices is an index? But I do not want to "hardcode" the position into the test, just filter with getters: get.id("id1"). is it possible? – arena Jun 29 '18 at 16:43
  • That's right, each item in the indices array is an index to the specific data item (row) in your data provider output. For more complex filtering, you could also move the data provider into a separate class and annotate it there (in this case you need to specify the dataProviderClass in your @Test annotation as well). I'm not aware of any more elegant ways of filtering your input data than just implementing your own filter. – t6nn Jun 29 '18 at 16:47
  • Thanks, it is a good info, but I need to wait the filter option. – arena Jun 29 '18 at 17:00
  • Data provider methods can also take a Method as a parameter - to make the filtering a bit easier for you. When a test is run, a reference to that test method is passed to your data provider. You could, for instance, define your own annotation for test methods and extract that from the provided Method reference. But then again, it's not too much different from hardcoding the indices. – t6nn Jun 29 '18 at 17:01