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:
Step 1: Recall TestNG test method syntax
A test method must be annotated with @Test before the method signature.
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.
Final Answer:
@Test public void testMethod() {} -> Option D
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
Master "TestNG Integration" in Selenium Java
9 interactive learning modes - each teaches the same concept differently