Bird
0
0

Identify the error in the following TestNG code snippet:

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

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

@AfterMethod
public void teardown() {
  System.out.println("Teardown")
}
AMissing semicolon in teardown method
BMissing @Test annotation on setup method
CIncorrect method access modifiers
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax in each method

    In teardown method, the print statement misses a semicolon at the end.
  2. Step 2: Verify annotations and modifiers

    setup and teardown methods have correct annotations and public access; test method is annotated properly.
  3. Final Answer:

    Missing semicolon in teardown method -> Option A
  4. Quick Check:

    Syntax error due to missing semicolon = C [OK]
Quick Trick: Check semicolons in print statements [OK]
Common Mistakes:
MISTAKES
  • Ignoring missing semicolon errors
  • Confusing annotations with access modifiers
  • Assuming code compiles without semicolons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes