Which annotation is used to define a test method in TestNG?
A) @Test
B) @TestMethod
C) @BeforeTest
D) @AfterTest
Answer:
A) @Test
Explanation:
The @Test
annotation in TestNG is used to define a test method. Any method annotated with @Test
will be treated as a test case by the TestNG framework and will be executed during the test run.
For example:
@Test
public void testMethod() {
// Test code here
}
In this example, testMethod()
is a test case that will be executed by TestNG.