Search code examples
javaannotationstestngselendroid

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 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()


Solution

  • 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.