TestNG vs Junit 4

Junit 4  and TestNG are similar on surface where as Junit 4 is designed for unit test. TestNg is high label testing it specially use very large and complex test suite.TestNg has some feature which are not in Junit 4.
Below are compression of TestNG and Junit 4 feature


TestNG
Junit
Annotation support
yes
yes
Exception Test
yes
yes
Ignore Test
yes
yes
TimeOut Test
yes
yes
Suite Test
yes
yes
Group Test
yes
no
Parametrized Test
yes
yes
Parametrized Test object
yes
no
Dependency Test
yes
no

Annotation are similar in both testNg and Junit 4 below are annotation compression.


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

No comments:

Post a Comment

Leave your comments, queries, suggestion I will try to provide solution