Comparison between JUnit and TestNG
| 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) |
1)
JUnit 4 : @BeforeClass and @AfterClass method as static method.
TestNG is more flexible in method declaration, it does not have this constraints.
2) Exception Test
JUnit4 : @Test(expected = ArithmeticException.class)
TestNG: @Test(expectedExceptions = ArithmeticException.class)
3) Ignore Test
JUnit4: @Ignore("Not Ready to Run")
TestNG: @Test(enabled=false)
4) Group Test , Parameterized Test, Dependency Test are more robust and advance Testing tools in TestNG.
No comments:
Post a Comment