Bird
0
0

Why does the following TestNG test class fail to run any tests?

medium📝 Debug Q7 of 15
Selenium Java - TestNG Integration
Why does the following TestNG test class fail to run any tests?
public class TestClass {
  @BeforeMethod
  public void setup() {}

  public void testMethod() {}

  @AfterMethod
  public void cleanup() {}
}
AtestMethod() is missing @Test annotation
Bsetup() method is private
Ccleanup() method has wrong return type
DClass is missing @Test annotation
Step-by-Step Solution
Solution:
  1. Step 1: Check which methods are tests

    Only methods annotated with @Test are executed as tests; testMethod lacks @Test annotation.
  2. Step 2: Verify other method correctness

    setup and cleanup have correct annotations and signatures; class-level @Test annotation is not required.
  3. Final Answer:

    testMethod() is missing @Test annotation -> Option A
  4. Quick Check:

    Tests need @Test annotation = D [OK]
Quick Trick: Only methods with @Test run as tests [OK]
Common Mistakes:
  • Thinking @BeforeMethod marks test methods
  • Assuming class needs @Test annotation
  • Confusing method access modifiers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes