Bird
0
0

How can you ensure that a setup method runs before any test methods, regardless of their priority or dependencies in TestNG?

hard📝 Application Q9 of 15
Selenium Java - TestNG Integration
How can you ensure that a setup method runs before any test methods, regardless of their priority or dependencies in TestNG?
ASet priority=0 on the setup method
BAnnotate the setup method with @BeforeClass
CUse dependsOnMethods on all tests to depend on setup
DAnnotate the setup method with @Test(enabled=false)
Step-by-Step Solution
Solution:
  1. Step 1: Understand TestNG lifecycle annotations

    @BeforeClass runs once before any test methods in the class, independent of priority or dependencies.
  2. Step 2: Evaluate other options

    Setting priority or dependsOnMethods is unreliable for setup; disabling test prevents execution.
  3. Final Answer:

    Annotate the setup method with @BeforeClass -> Option B
  4. Quick Check:

    Setup before tests = @BeforeClass B [OK]
Quick Trick: Use @BeforeClass for setup before all tests [OK]
Common Mistakes:
MISTAKES
  • Using priority for setup order
  • Making all tests depend on setup manually
  • Disabling setup method with enabled=false

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes