Bird
0
0

Which of the following is the correct way to declare a TestNG test method?

easy📝 Syntax Q3 of 15
Selenium Java - TestNG Integration
Which of the following is the correct way to declare a TestNG test method?
Apublic @Test void testMethod() {}
Bpublic void testMethod() {}
Cvoid @Test testMethod() {}
D@Test public void testMethod() {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall TestNG test method syntax

    A test method must be annotated with @Test before the method signature.
  2. Step 2: Check each option

    @Test public void testMethod() {} correctly places @Test before the method declaration. Options C and D have incorrect syntax, and B lacks the annotation.
  3. Final Answer:

    @Test public void testMethod() {} -> Option D
  4. Quick Check:

    @Test annotation before method = A [OK]
Quick Trick: Always place @Test before method signature [OK]
Common Mistakes:
  • Placing @Test after method name
  • Omitting @Test annotation
  • Incorrect method modifiers order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes