Bird
0
0

What is wrong with this TestNG test method if we want testB to run only after testA completes successfully?

medium📝 Debug Q14 of 15
Selenium Java - TestNG Integration
What is wrong with this TestNG test method if we want testB to run only after testA completes successfully?
@Test
public void testA() { }

@Test(dependsOnMethods = {"testA"})
public void testB() { }

@Test(dependsOnMethods = {"testC"})
public void testC() { }
AtestA should have dependsOnMethods attribute
BtestB does not depend on testA correctly
CNo errors, code is correct
DtestC depends on itself, causing a circular dependency error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze dependencies declared

    testB depends on testA, which is correct. testC depends on "testC" itself, which is a circular dependency.
  2. Step 2: Understand circular dependency impact

    A test depending on itself causes TestNG to throw an error and stop execution.
  3. Final Answer:

    testC depends on itself, causing a circular dependency error -> Option D
  4. Quick Check:

    Self-dependency causes error [OK]
Quick Trick: Avoid tests depending on themselves [OK]
Common Mistakes:
  • Thinking testB dependency is wrong
  • Adding dependsOnMethods to testA unnecessarily
  • Ignoring circular dependency errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes