Bird
0
0

Identify the error in the following TestNG code snippet:

medium📝 Debug Q14 of 15
Selenium Java - TestNG Integration
Identify the error in the following TestNG code snippet:
public class TestExample {
  @BeforeMethod
  public void setup() {
    System.out.println("Setup");
  }

  @Test
  public void testMethod() {
    System.out.println("Test");
  }

  @AfterMethod
  public void cleanup() {
    System.out.println("Cleanup")
  }
}
AMissing semicolon after System.out.println("Cleanup")
BIncorrect annotation @AfterMethod should be @AfterTest
Csetup() method should be static
DtestMethod() must return boolean
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax in cleanup() method

    The line System.out.println("Cleanup") is missing a semicolon at the end.
  2. Step 2: Verify other parts

    Annotations are correct, methods do not need to be static, and test methods can be void.
  3. Final Answer:

    Missing semicolon after System.out.println("Cleanup") -> Option A
  4. Quick Check:

    Java statements must end with semicolon [OK]
Quick Trick: Check for missing semicolons in Java code [OK]
Common Mistakes:
MISTAKES
  • Confusing @AfterMethod with @AfterTest
  • Thinking test methods must return boolean
  • Assuming setup() must be static

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes