Which annotation is used to run a method after each test method in TestNG?
A) @AfterMethod
B) @AfterClass
C) @AfterTest
D) @AfterSuite
Answer:
A) @AfterMethod
Explanation:
The @AfterMethod
annotation in TestNG is used to run a method after each test method. This annotation is typically used for cleanup tasks, such as resetting states or releasing resources used during the test.
For example:
@AfterMethod
public void tearDown() {
// Code to clean up after each test method
}
In this example, tearDown()
will be executed after each test method in the class.