TestNG

TestNG is a framework for testing of Java programs, especially for the automated unit testing of individual units ( classes or methods ) is appropriate. It is based on well-known concepts from JUnit and NUnit but this added new functionalities.

New functionalities

TestNG provides some functionalities that are not present in most other representatives of xUnit frameworks:

With TestNG can be certain parts of an application with respect to test concurrency by allowing run in parallel threads whose tests. Therefore, it is with TestNG on the one hand the possible tests of certain test suites to run with any number of threads simultaneously. Different procedures can it be determined per test suite: all the test methods in a separate thread, all the same tagged test methods in a separate thread, all the test methods in the same test class in a separate thread and all the test methods of the same instance of the test class in a separate thread. On the other hand, it is per test method to determine possible that they should be called multiple times by different threads.

TestNG allows for flexible grouping of tests and test methods via XML configuration or annotations. For example, to test for different test levels (such as unit testing, integration testing, acceptance testing ) or test environments can be selected. Groups can be selected, grouped with other groups again or also excludes also using regular expressions.

Test methods can be controlled in TestNG with parameters. This is possible using XML configuration and by means of annotations. The parameters can be passed directly or generated by so-called data provider at runtime. This makes it possible for the time of execution of the tests to take on the runtimes of the tests into consideration. The data provider can also provide different data for a test method, this lead to several test runs of a test method with different data. Thus, it is possible to perform with TestNG data-driven test runs. This simple, the data coverage of the tests are increased. The annotation @ Factory offers more opportunities to at runtime to run multiple distinct instances of a test.

TestNG generates test reports in HTML and XML format. Since version 4.6 TestNG also has a programming interface for reporting. This further report can be generators such as ReportNG or TestNG - XSLT used.

Use

A test class can look at TestNG as follows:

Public class Test1 {     @ Test ( groups = {" functest ", " checkintest "} )     public void TestMethod1 () {     }       @ Test ( groups = {" functest ", " checkintest "} )     public void testMethod2 () {     }       @ Test ( groups = {" functest "} )     public void testMethod3 () {     } } There are some helpful annotations such as @ Before Suite | @ After Suite | @ DataProvider

A test suite can be compiled via an XML document

                                                      < / groups >                                                         < / class>       < / classes >     < / test > < / suite > tool support

TestNG is supported by a number of development tools, either directly or by means of plugins. All major Java development environments, Eclipse, IntelliJ IDEA and NetBeans IDE support TestNG. Furthermore, it is also supported by all major Java build management tools, Apache Maven, Apache Ant and Gradle. Systems for continuous integration as Hudson and Jenkins also support TestNG and may represent test results over time. Many tools to measure test coverage such as Cobertura also support TestNG.

766277
de