Bird
0
0

Which of the following is the correct syntax to make testB depend on testA in TestNG?

easy📝 Syntax Q12 of 15
Selenium Java - TestNG Integration
Which of the following is the correct syntax to make testB depend on testA in TestNG?
A@Test(dependsOnMethods = testA) public void testB() {}
B@Test(dependsOnMethods = {"testA"}) public void testB() {}
C@Test(dependsOn = "testA") public void testB() {}
D@Test(dependOn = "testA") public void testB() {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall TestNG annotation syntax

    The correct attribute name is dependsOnMethods and it expects an array of method names as strings.
  2. Step 2: Check the syntax correctness

    @Test(dependsOnMethods = {"testA"}) public void testB() {} correctly uses @Test(dependsOnMethods = {"testA"}) with the method name in quotes inside braces.
  3. Final Answer:

    @Test(dependsOnMethods = {"testA"}) public void testB() {} -> Option B
  4. Quick Check:

    dependsOnMethods requires string array syntax [OK]
Quick Trick: Use dependsOnMethods with braces and quotes [OK]
Common Mistakes:
  • Using dependsOn instead of dependsOnMethods
  • Omitting quotes around method name
  • Not using braces for the array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes