Bird
0
0

Which statement best describes the execution behavior of @BeforeMethod and @AfterMethod in TestNG when tests are run in parallel?

hard📝 Conceptual Q10 of 15
Selenium Java - TestNG Integration
Which statement best describes the execution behavior of @BeforeMethod and @AfterMethod in TestNG when tests are run in parallel?
A@BeforeMethod runs before all tests, @AfterMethod runs after all tests in parallel
B@BeforeMethod and @AfterMethod run sequentially regardless of parallel tests
C@BeforeMethod and @AfterMethod run in the same thread as their test method
D@BeforeMethod and @AfterMethod run in separate threads from test methods
Step-by-Step Solution
Solution:
  1. Step 1: Understand TestNG parallel execution model

    When tests run in parallel, @BeforeMethod and @AfterMethod execute in the same thread as their corresponding test method.
  2. Step 2: Evaluate options

    @BeforeMethod and @AfterMethod run in the same thread as their test method correctly states this. @BeforeMethod and @AfterMethod run sequentially regardless of parallel tests is false because parallel tests run concurrently. Options C and D incorrectly describe execution threads.
  3. Final Answer:

    @BeforeMethod and @AfterMethod run in the same thread as their test method -> Option C
  4. Quick Check:

    Config methods run in test thread during parallel execution = A [OK]
Quick Trick: Config methods run in test thread during parallel runs [OK]
Common Mistakes:
  • Assuming config methods run sequentially always
  • Thinking config methods run in separate threads
  • Confusing before/after all tests with per-test methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes