Skip to main content
Home
  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact
programsbuzz facebook programsbuzz twitter programsbuzz linkedin
  • Log in

Main navigation

  • Tutorials
    • Quality Assurance
    • Software Development
    • Machine Learning
    • Data Science
  • About Us
  • Contact

Introduction to TestNG and its Benefits

Profile picture for user ksharma
Written by ksharma on 10/07/2020 - 20:52

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use. With the help of testNG we can achieve our testing requirements like functional, regression, sanity and end-to-end testing and more. It is an open-source automated testing framework; where NG of TestNG means Next Generation.

TestNG is a testing framework for the Java programming language created by Cédric Beust.

Benefits of using TestNG

  • Reporting: Default Selenium tests do not generate a proper format for the test results. Using TestNG we can generate test results. It generate the report in a proper format including a number of test cases runs, the number of test cases passed, the number of test cases failed, and the number of test cases skipped.
  • Grouping of Test Cases: Multiple test cases can be grouped more easily by converting them into testng.xml file. 
  • Invocation Count: The same test case can be executed multiple times without loops just by using keyword called 'invocation count.'
  • Cross browser Testing: Using testng, you can execute multiple test cases on multiple browsers.
  • Integration with Maven and Jenkins: The testing framework can be easily integrated with tools like Maven, Jenkins, etc.
  • Annotations: Annotations used in the testing are very easy to understand eg: @BeforeMethod, @AfterMethod, @BeforeTest, @AfterTest. It provide more annotations then JUNIT, this means more control over test and suite.
  • Parallel Testing: TestNG provide support for parallel Testing. You can execute multiple threads at same time.
  • Execution without main: You can execute your test without using main and by tagging the method with @Test.
  • Parameterization: Parameterized tests allow developers to run the same test over and over again using different values. With this technique, you define the simple parameters in the testng.xml file and then reference those parameters in the source files.
  • Data Driven Testing: You can use Data Provider in TestNG. Data Provider in TestNG is a method used when a user needs to pass complex parameters. Complex Parameters need to be created from Java such as complex objects, objects from property files or from a database can be passed by the data provider method. 
  • Test Prioritization: You can assign priority to test methods.
  • Test Dependency: It allow dependency of one test case over other test case.
  • Logs: Logs can be generated using TestNG using its reporter class.

Sample TestNG File

!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
  
<suite name="Suite1" verbose="1" >
  <test name="Nopackage" >
    <classes>
       <class name="NoPackageTest" />
    </classes>
  </test>
 
  <test name="Regression1">
    <classes>
      <class name="test.sample.ParameterSample"/>
      <class name="test.sample.ParameterTest"/>
    </classes>
  </test>
</suite>

In above file 

  • A suite is represented by one XML file. It can contain one or more tests and is defined by the <suite> tag.
  • A test is represented by <test> and can contain one or more TestNG classes.
  • A TestNG class is a Java class that contains at least one TestNG annotation. It is represented by the <class> tag and can contain one or more test methods.

XML file contains more content this sample one, which we will discuss later in more detail.

Tags
TestNG
  • Log in or register to post comments

Choose Your Technology

  1. Agile
  2. Apache Groovy
  3. Apache Hadoop
  4. Apache HBase
  5. Apache Spark
  6. Appium
  7. AutoIt
  8. AWS
  9. Behat
  10. Cucumber Java
  11. Cypress
  12. DBMS
  13. Drupal
  14. GitHub
  15. GitLab
  16. GoLang
  17. Gradle
  18. HTML
  19. ISTQB Foundation
  20. Java
  21. JavaScript
  22. JMeter
  23. JUnit
  24. Karate
  25. Kotlin
  26. LoadRunner
  27. matplotlib
  28. MongoDB
  29. MS SQL Server
  30. MySQL
  31. Nightwatch JS
  32. PactumJS
  33. PHP
  34. Playwright
  35. Playwright Java
  36. Playwright Python
  37. Postman
  38. Project Management
  39. Protractor
  40. PyDev
  41. Python
  42. Python NumPy
  43. Python Pandas
  44. Python Seaborn
  45. R Language
  46. REST Assured
  47. Ruby
  48. Selenide
© Copyright By iVagus Services Pvt. Ltd. 2023. All Rights Reserved.

Footer

  • Cookie Policy
  • Privacy Policy
  • Terms of Use