img

TestNG vs JUnit

JUnit and TestNG are very popular unit testing frameworks for java software developers and we can use them in our webdriver test execution for any software web application.

Similarities Between JUnit and TestNG

  1. We can create test suite in JUnit and TestNG both frameworks.
  2. Timeout Test Is possible very easily in both the frameworks.
  3. We can ignore specific test case execution of software web application from suite in both the frameworks.
  4. It is possible to create expected exception test for software web application in both the frameworks.
  5. Annotations – Few annotations are similar in both frameworks suite like @Test, @BeforeClass, @AfterClass. JUnit’s Annotations @Before and @After are similar to TestNG’s @BeforeMethod and @AfterMethod annotations.
Difference Between JUnit and TestNG
  1. In TestNG, Parameterized test configuration is very easy while It is very hard to configure Parameterized test in JUnit.
  2. TestNG support group test but it is not supported in JUnit.
  3. TestNG has a feature to configure dependency test. Dependency test configuration for software web application is not possible in JUnit.
  4. TestNG support @BeforeTest, @AfterTest, @BeforeSuite, @AfterSuite, @BeforeGroups, @AfterGroups which are not supported in JUnit.
  5. Test prioritization, Parallel testing is possible in TestNG. It is not supported by JUnit.

Annotation Support

Feature 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)
  • Facebook
  • Twitter
  • Google+
  • Linkedin
  • Pinterest

Leave a Comment

Your email address will not be published. Required fields are marked *

It is main inner container footer text