How to use testng annotations in java
My code
public class Test{
@BeforeTest
public void create_user throws Exception (){
}
@Test
public void user_actions throws Exception (){
}
@AfterTest
public void delete_user throws Exception(){
}
}
Above is my test class. If I get an error in create_user()
, it is currently being thrown Exception
and finished with the test case.
But I need delete_user()
to execute regardless of any error in create_user()
oruser_actions()
+3
source to share
3 answers
Try it @AfterTest(alwaysRun = true)
.
From TestNG doc :
For the following methods (afterSuite, afterClass, ...): if set to true, this configuration method will run even if one or more of the previously called methods failed or were skipped.
+4
source to share