Bird
0
0

What is wrong with this test method using a DataProvider?

medium📝 Debug Q7 of 15
Selenium Java - TestNG Integration
What is wrong with this test method using a DataProvider?
@Test(dataProvider = "data")
public void test(int a, int b) {
  System.out.println(a + b);
}

@DataProvider(name = "data")
public Object[][] getData() {
  return new Object[][] { {1}, {2, 3} };
}
AData sets have inconsistent parameter counts
BDataProvider name is missing
CTest method parameters should be Strings
DDataProvider method must be private
Step-by-Step Solution
Solution:
  1. Step 1: Compare test method parameters and data sets

    The test method expects two int parameters, but the first data set has only one value.
  2. Step 2: Identify mismatch issue

    DataProvider must supply data sets matching the test method's parameter count; inconsistent counts cause runtime errors.
  3. Final Answer:

    Data sets have inconsistent parameter counts -> Option A
  4. Quick Check:

    DataProvider data must match test method parameters [OK]
Quick Trick: Each data set must match test method parameter count [OK]
Common Mistakes:
  • Ignoring parameter count mismatch
  • Assuming DataProvider name is optional
  • Thinking parameters must be Strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes