What is the purpose of the @AfterSuite annotation in TestNG?
A) To execute a method after all tests in a suite
B) To execute a method before all tests in a suite
C) To execute a method after each test method
D) To execute a method before each test method
Answer:
A) To execute a method after all tests in a suite
Explanation:
The @AfterSuite
annotation in TestNG is used to execute a method after all tests in a suite have run. This annotation is typically used for cleanup tasks or for generating reports after all tests have been executed.
For example:
@AfterSuite
public void tearDownSuite() {
// Code to clean up after all tests in the suite
}
In this example, tearDownSuite()
will be executed once after all the test methods in the suite have been run.