Bird
0
0

Which TestNG annotation is used to run a method after each test method in a class?

easy📝 Conceptual Q1 of 15
Selenium Java - TestNG Integration
Which TestNG annotation is used to run a method after each test method in a class?
A@AfterMethod
B@BeforeClass
C@AfterClass
D@BeforeMethod
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of @AfterMethod

    The @AfterMethod annotation runs a method after each test method in the class finishes.
  2. Step 2: Compare with other annotations

    @BeforeClass and @AfterClass run once before/after all tests, @BeforeMethod runs before each test, so only @AfterMethod fits the requirement.
  3. Final Answer:

    @AfterMethod -> Option A
  4. Quick Check:

    Runs after each test = @AfterMethod [OK]
Quick Trick: After each test method runs, @AfterMethod executes [OK]
Common Mistakes:
  • Confusing @AfterMethod with @AfterClass
  • Thinking @BeforeMethod runs after tests
  • Mixing @BeforeClass with per-test annotations

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes