TestNG Test Suite (2024) | TechGeekNext

TestNG Test Suite (2024)

In this tutorial, we will understand TestNG Test Suite and how to create a multiple test suite and run it.

Q: What is the TestNG test Suite?
Ans:

A test suite of software programs is a collection of test cases that are used to test a behavior or a set of behaviors. As suite is the feature of execution it is represented by an XML file and not defined in the testing source code in testNG.

The tests are run with a flexible configuration. A suite can consist of one or more tests. The suite is interpreted as <suite>. The foundation of testng.xml is <suite>.

A test suite is described from it and many <test> sections are made from it.

Following are attributes with their descriptions that accept the<suite>:

  1. Name: The compulsory attribute is the name of the suite.
  2. parallel: Parallel will help TestNG to decide whether it should run different threads to run this suite.
  3. Annotations: In your tests type of annotations is used.
  4. verbose: The level for the run.
  5. Thread count: The number of threads that are used. No need to count thread if Parallel mode is selected.
  6. Time count: The time used for completing all the test methods found in this test.

Let's two examples run together using the test suite.

The XML file will be created and it will be the main spot file where you configure your test run. Test dependency is set, exclude, or include any test, class, package, method, set priority, etc.

How TestNG XML is created?

Following are the steps to create a TestNG XML File for running the TestNG test suite:

  1. As given in the below image, Right-click on the Project folder->TestNG->Convert to TestNG.
  2. TestNG XML
  3. Provide the file name -> remove the thread count (we can edit as per our needs)->Click Finish.
  4. TestNG XML
  5. It will create testng.xml file, edit and make two tests as below:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
    <suite name="Suite">
      <test name="Test1">
        <classes>
          <class name="com.techgeeknext.testcases.DatabaseTestCases"/>
        </classes>
      </test> <!-- Test -->
      <test name="Test2">
        <classes>
        <class name="com.techgeeknext.testcases.LoginTestCases"/>
        </classes>
      </test> <!-- Test -->
    </suite> <!-- Suite -->
    This TestNG XML code is very easy to write and understand. As per above code have created multiple tests.
    • Suite Name: Any suite name can be given and it will relate to the test suite name and it is written as <suite>.
    • Test Name: Any test name can be given and will indicate test sets. It is written as <test>.
    • Classes Name: Any name cannot be given to the classes as it is the combination of package and test case name. It is written as <classes>.
  6. TestNG XML is created -> Run the TestNG suite.
  7. Right-click on the testng.xml file-> Run As-> TestNG Suite. TestNG XML
  8. After running the TestNG Suite, below result is obtained as given below: TestNG XML Output

Recommendation for Top Popular Post :