Feature | JUnit 4 | TestNG |
test annotation | @Test | @Test |
run before all tests in this suite have run | – | @BeforeSuite |
run after all tests in this suite have run | – | @AfterSuite |
run before the test | – | @BeforeTest |
run after the test | – | @AfterTest |
run before the first test method that belongs to any of these groups is invoked | – | @BeforeGroups |
run after the last test method that belongs to any of these groups is invoked | – | @AfterGroups |
run before the first test method in the current class is invoked | @BeforeClass | @BeforeClass |
run after all the test methods in the current class have been run | @AfterClass | @AfterClass |
run before each test method | @Before | @BeforeMethod |
run after each test method | @After | @AfterMethod |
ignore test | @ignore | @Test(enbale=false) |
expected exception | @Test(expected = ArithmeticException.class) | @Test(expectedExceptions = ArithmeticException.class) |
timeout | @Test(timeout = 1000) | @Test(timeout = 1000) |