TestNG

from Wikipedia, the free encyclopedia
TestNG
Basic data

developer Cédric Beust, Alexandru Popescu and others
Current  version 7.1.1
( December 19, 2019 )
operating system cross-platform
programming language Java
category Test - Framework
License Apache license 2.0
German speaking No
testng.org

TestNG is a framework for testing of Java programs, which particularly for automated unit testing of individual units ( classes or methods is suitable). It builds on well-known concepts from JUnit and NUnit , but supplements them with new functionalities.

New functionalities

TestNG contains some functionalities that most of the other representatives of xUnit frameworks do not have:

With TestNG, certain parts of an application can be tested for concurrency by running their tests in parallel threads. On the one hand, TestNG makes it possible to run the tests of certain test suites with any number of threads at the same time. Different procedures can be determined for each test suite: all test methods in a separate thread, all identically tagged test methods in a separate thread, all test methods of the same test class in a separate thread and all test methods of the same instance of the test class in a separate thread. On the other hand, it is possible to determine for each test method that it should be called several times and by different threads.

TestNG enables a flexible grouping of tests and test methods using XML configuration or annotations. For example, tests for different test levels (such as module tests, integration tests, acceptance tests) or test environments can be selected. Groups can also be selected using regular expressions, combined into other groups, or excluded.

Test methods can be controlled in TestNG using parameters. This is possible both by means of XML configuration and by means of annotations. The parameters can be transferred directly or generated at runtime using a so-called data provider. This makes it possible to take into account the runtime environments of the tests when the tests are executed. The DataProviders can also deliver different data for a test method; these then lead to several test runs of a test method with different data. Thus, with TestNG it is possible to carry out data-driven test runs. This can easily increase the data coverage of the tests. The annotation @Factoryoffers further possibilities to run several different instances of a test at runtime.

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

use

A test class can look like this under TestNG:

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 @BeforeSuite | @AfterSuite | @DataProvider

A test suite can be compiled from an XML document

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1"  verbose="1" >
   <test name="Regression1">
     <groups>
       <run>
         <exclude name="brokenTests" />
         <include name="checkinTests" />
       </run>
     </groups>

     <classes>
       <class name="test.IndividualMethodsTest">
         <methods>
           <include name="testMethod" />
         </methods>
       </class>
     </classes>
   </test>
</suite>

Tool support

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

See also

literature

  • Cedric Beust, Hani Suleiman: Next Generation Java Testing . TestNG and Advanced Concepts. Addison-Wesley, Amsterdam 2007, ISBN 978-0-321-50310-7 (English).
  • Tomek Kaczanowski: Practical Unit Testing with TestNG and Mockito . Ed .: Tomek Kaczanowski. 2012, ISBN 978-83-934893-0-5 (English).

Web links

Individual evidence

  1. Release 7.1.1 . December 19, 2019 (accessed December 20, 2019).
  2. Announcing TestNG 4.6
  3. ReportNG 1.0 Final Released
  4. TestNG XSL Reports
  5. TestNG annotations