Bird
0
0

What is the main purpose of the @BeforeMethod annotation in TestNG?

easy📝 Conceptual Q11 of 15
Selenium Java - TestNG Integration
What is the main purpose of the @BeforeMethod annotation in TestNG?
ATo run a method before each test method to set up the test environment
BTo mark a method as a test case
CTo run a method after all test methods have finished
DTo skip a test method during execution
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of @BeforeMethod

    This annotation is used to run a method before each test method to prepare or set up the environment.
  2. Step 2: Differentiate from other annotations

    @Test marks test methods, @AfterMethod runs after each test, and skipping tests uses other annotations.
  3. Final Answer:

    To run a method before each test method to set up the test environment -> Option A
  4. Quick Check:

    @BeforeMethod = setup before each test [OK]
Quick Trick: BeforeMethod always runs before each test method [OK]
Common Mistakes:
MISTAKES
  • Confusing @BeforeMethod with @BeforeClass
  • Thinking @BeforeMethod runs only once
  • Mixing @BeforeMethod with @AfterMethod

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes