Bird
0
0

What will be the output when the following test runs?

medium📝 Predict Output Q5 of 15
Selenium Java - TestNG Integration
What will be the output when the following test runs?
@DataProvider(name = "words")
public Object[][] data() {
  return new Object[][] { {"apple"}, {"banana"} };
}

@Test(dataProvider = "words")
public void printWord(String word) {
  System.out.println(word.length());
}
A6 and 5
Bapple and banana
C5 and 6
DError at runtime
Step-by-Step Solution
Solution:
  1. Step 1: Analyze DataProvider data

    The DataProvider returns two strings: "apple" and "banana".
  2. Step 2: Understand test method output

    The test prints the length of each string: "apple" has 5 letters, "banana" has 6 letters.
  3. Final Answer:

    5 and 6 -> Option C
  4. Quick Check:

    Output = string lengths from DataProvider inputs [OK]
Quick Trick: Test prints length of each string from DataProvider [OK]
Common Mistakes:
MISTAKES
  • Printing strings instead of lengths
  • Swapping output order
  • Expecting runtime errors without cause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes