Comparison of junit with testng

JUnit is the oldest unit testing framework. TestNG came in the industry much later after JUnit. Here are the major difference between JUnit and TestNG frameworks.
  • JUnit tests can not be executed in specific order. In TestNG, we can execute the tests in desired order.
  • before and after group hooks are available in TestNG.
  • BeforeSuite and AfterSuite hooks are available in TestNG. In JUnit we do not run tests using suite XML file So we do not have before and after suite hooks.
  • In TestNG, tests can depend on other tests. In JUnit, we do not have such feature.
  • JUnit does not create any test execution report. TestNG creates HTML report which includes details like which test classes were executed, which tests failed, how much time was taken for test execution
  • We can run failed only tests in TestNG using failed-testNG.xml file in output directory. In JUnit, we can not run failed only tests.
  • We can run junit tests from TestNG but not vice versa
  • We can put @Test annotation at class level in TestNG but not in JUnit

Web development and Automation testing

solutions delivered!!