Bird
0
0

You want to run a setup method before each test but only for tests in a specific group named "smoke". Which TestNG annotation usage is correct?

hard📝 Application Q8 of 15
Selenium Java - TestNG Integration
You want to run a setup method before each test but only for tests in a specific group named "smoke". Which TestNG annotation usage is correct?
A@BeforeMethod(onlyForGroups = "smoke")
B@BeforeMethod(alwaysRun = true, groups = "smoke")
C@BeforeMethod(groups = "smoke")
D@BeforeMethod(onlyForGroups = {"smoke"})
Step-by-Step Solution
Solution:
  1. Step 1: Recall @BeforeMethod group filtering syntax

    @BeforeMethod supports a groups attribute to specify which test groups it applies to.
  2. Step 2: Evaluate options

    @BeforeMethod(groups = "smoke") correctly uses groups = "smoke". Options A and D use invalid attribute onlyForGroups, and C mixes alwaysRun unnecessarily.
  3. Final Answer:

    @BeforeMethod(groups = "smoke") -> Option C
  4. Quick Check:

    Use groups attribute to filter @BeforeMethod = B [OK]
Quick Trick: Use groups="groupName" to limit @BeforeMethod [OK]
Common Mistakes:
  • Using non-existent onlyForGroups attribute
  • Confusing alwaysRun with groups
  • Not using quotes for group names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes