Javatpoint Logo
Javatpoint Logo

TestNG @AfterMethod Annotation

The @AfterMethod annotation is specific to a class not to an XML file. The @AfterMethod annotated method will be invoked after the execution of each test method. Suppose there are four test methods means that @AfterMethod annotated method will be executed four times.

Let's understand the @AfterMethod annotation through an example.

Step 1: Open the Eclipse.

Step 2: We create a simple java project which contains the @AfterMethod annotated method.

Step 3: Now, we create a testng.xml file to configure After_Method class.

Step 4: Run the testng.xml file. Right click on the testng.xml file and move the cursor down to Run As, and then click on the 1 TestNG Suite.


TestNG @AfterMethod Annotation

Note: TestNG executes the test methods in alphabetical order.

In the above case, first c_programmers() method runs, then @AfterMethod annotated method is executed, thereafter dotnet_developer() method runs, then @AfterMethod annotated method is executed, and at the last java_programmers() method run, and then @AfterMethod annotated method will be executed.

Next TopicTestNG Annotations

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA