TestNG 5.0 - new annotations and more

| | bookmark | email | 2 comments
TestNG 5.0 - new annotations and more The new version of TestNG was released. Cedric made the first announcement and the news spreaded quite fast.
The main addition in the new version are the completely revamped annotations. The old @Configuration was replaced by more clear and much more readable annotations: @Before/AfterSuite, @Before/AfterTest, @Before/AfterGroup, @Before/AfterClass, @Before/AfterMethod (phewww... quite a few). But check the following code to see how much better it is:
The "old" way:
public class MethodCallOrderTest {
  @Configuration(beforeTestClass=true)
  public void beforeClass() {
     // do before any test methods in this class are executed
  }
  
  @Configuration(beforeTestMethod=true)
  public void beforeMethod() {
     // do before each test method
  }
  
  @Test
  public void realTest() {
  }
  
  @Configuration(afterTestMethod=true)
  public void afterMethod() {
     // do after each test method
  }
  
  @Configuration(afterTestClass=true)
  public void afterClass() {
  }

  @Configuration(afterSuite=true)
  public void cleanUp() {
      // do once after all tests
  }

}
new way:
public class MethodCallOrderTest {
  @BeforeClass
  public void beforeClass() {
     // hey it looks like I don't need to put any comment here to explain it, ain't it?
  }

  @BeforeMethod
  public void beforeMethod() {
  }
  
  @Test
  public void realTest() {
  }
  
  @AfterMethod
  public void afterMethod() {
  }
  
  @AfterClass
  public void afterClass() {
  }
  
  @AfterSuite
  public void cleanUp() {
  }
}
There are a lot more improvements in this new version: better reports, filtered stack traces, more configuration options for the Ant task.
Last, but not least: don't worry about the next versions. We already have in mind a couple of more nice things that will make life easier and a lot more pleasant for test developers.