MorkPuncher February 2016

TestNG global @AfterMethod

In java TestNG is it possible to somehow specify a global (or suite wide) method with @AfterMethod annotation? The goal is to have different testcases in seperate classes(so that 1 file = 1 test) but to also have a common @AfterMethod without duplicating the method in every class.

Answers


David Baak February 2016

You can achieve this by making a superclass. Example:

public class BasicTestScenario {

  @AfterMethod(alwaysRun=true)
  public void tearDown() {
    // your implementation
  }
}

Then have your tests inherit this class.

public class MyTest extends BasicTestScenario {
// your test
}

Post Status

Asked in February 2016
Viewed 3,118 times
Voted 5
Answered 1 times

Search




Leave an answer