TestNG is a testing framework for the Java programing language created by CédricBeust and impressed by JUnit and NUnit. The design goal of TestNG is to hide a wider vary of take a look at categories: unit, functional, end-to-end, integration, etc., with a lot of powerful and easy-to-use functionalities.
TestNG’s main features include:
- Annotation support.
- Support for parameterized and data-driven testing (with @DataProvider and/or XML configuration).
- Support for multiple instances of constant take a look at category (with @Factory)
Flexible execution model.
TestNG can be run either by Ant via build.xml (with or without a test suite defined), or by an IDE plugin with visual results. There isn’t a TestSuite category, while test suites, groups and tests selected to run are defined and configured by XML files. Concurrent testing: run tests in every which way massive thread pools with numerous policies out there (all ways in their own thread, one thread per test class, etc.), and test whether the code is multithread safe.
- Embeds BeanShell for further flexibility.
- Default JDK functions for runtime and work (no dependencies).
- Dependent methods for application server testing.
- Distributed testing: permits distribution of tests on slave machines.
The variations between and several benefits of the 2 apparently competitory Java tools, TestNG and JUnit, have been debated throughout the decade. Both camps have strong grounds and supporters. Stackoverflow discussions reflect this controversy.
In JUnit 4, the @BeforeClass and @AfterClass methods have to be declared as static. TestNG does not have this constraint. TestNG has provided four further setup/teardown pairs for the suite, test and groups, i.e. @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeGroup and @AfterGroup, @BeforeMethod and @AfterMethod. TestNG give wide selection of support to automatize application mistreatment element.
This feature is enforced in each tools, however in quite different ways. TestNG has two ways for providing varying parameter values to a test method: by setting the testng.xml, and by defining a @DataProvider method. In JUnit 4, @RunWith and @Parameters are used together to facilitate parameterized tests, while the @Parameters method has to return List with all the actual values, which will be fed into a dedicated class constructor as an argument.
Testng interview questions is supported, out-of-the-box or via plug-ins, by each of the three major Java IDEs – Eclipse, IntelliJ IDEA, and NetBeans. It conjointly comes with a custom task for Apache hymenopterous insect and is supported by the whiz build system. The Hudson continuous integration server has built-in support for TestNG and is able to track and chart test results over time. Most Java code coverage tools, such as Cobertura, work seamlessly with TestNG.
TestNG generates take a look at reports in HTML and XML formats. The XML output may be reworked by the hymenopterous insect JUnitReport task to come up with reports just like those obtained once mistreatment JUnit. Since version 4.6, TestNG also provides a reporter AP that permits third-party report generators, such as ReportNG, PDFngreport and TestNG-XSLT, to be used.
JUnit is commonly shipped with thought day by default, which contributes to its wider popularity. However, TestNG’s goal is way wider, which includes not only unit testing, but also support of integration and acceptance testing, etc. Which one is best or a lot of appropriate depends on use contexts and needs.