Bird
0
0

Given the following code snippet, what will be the output when the test runs?

medium📝 Predict Output Q13 of 15
Selenium Java - TestNG Integration
Given the following code snippet, what will be the output when the test runs?
@DataProvider(name = "numbers")
public Object[][] data() {
    return new Object[][] { {1, 2}, {3, 4} };
}

@Test(dataProvider = "numbers")
public void testSum(int a, int b) {
    System.out.println(a + b);
}
ANo output because test is skipped
B1 and 2 printed on separate lines
C3 and 7 printed on separate lines
DCompilation error due to wrong DataProvider
Step-by-Step Solution
Solution:
  1. Step 1: Understand the DataProvider data

    The DataProvider returns two sets: {1, 2} and {3, 4}.
  2. Step 2: Calculate the sum for each test run

    First run: 1 + 2 = 3; second run: 3 + 4 = 7; both printed on separate lines.
  3. Final Answer:

    3 and 7 printed on separate lines -> Option C
  4. Quick Check:

    Sum of pairs = 3, 7 [OK]
Quick Trick: Sum each data pair printed per test run [OK]
Common Mistakes:
  • Assuming only one test run happens
  • Confusing data sets with single values
  • Expecting compilation errors without syntax issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes