Reputation: 6309
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 any error in create_user()
, currently its throws Exception
and ran out of the test case.
But i need delete_user()
should be executed irrespective of any error in create_user()
or user_actions()
Upvotes: 3
Views: 102
Reputation: 1701
If the test method should expect an exception, use the following annotation:
@Test(expectedExceptions=<your exceptions here>)
public void user_actions throws Exception (){
//
}
If the test method throws an unexpected exception, I would recommend to review your test setup/method.
Upvotes: 0
Reputation: 176
If the test exception is expected you can use @expected to inform the test about the exception which would ensure calling delete_user. If it is an adhoc exception having finally block to delete_user is a good practice.
Upvotes: 0
Reputation: 3628
Try @AfterTest(alwaysRun = true)
.
From the TestNG doc:
For after methods (afterSuite, afterClass, ...): If set to true, this configuration method will be run even if one or more methods invoked previously failed or was skipped.
Upvotes: 4