Test Suite in TestNG

Price: INR 1,299.00
Was: INR 1,799.00

Let’s see, What is Test Suite in TestNG. As we know Test Suite is something which is used to execute the test cases in a batch. We include many test cases in a single suite and run these test cases as the batch.

So running a set of test cases together is call executing a Test Suite.

 

In TestNG, we can create the test suite using testng.xmlfile. This testng.xml file is very important factor in TestNG, this file could be used for configuring your test run, set test dependency, include or exclude any test, method, class or package and set priority etc. We will see, How we can create this file and use it to make our execution process easier .

 

Video Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

 

How to create testng.xml file

We can create the testng.xml file from TestNG report but I would like to recommend you to follow the sample available on testng.org website.

You just need to copy this XML code and open create the notepad file and paste it. Save this file with name testng.xml . So you have created the sample testng.xml file, Now we are going to learn how we can edit this as per our use.

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd” >
  
<suite name=”Suite1″ >
  <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>

 

Now we are going to understand this file.  In this file first tag is Suite , We can provide any name in our suite tag. This name will display as our test suite name.

Next tag is Test name tag, Here you will provide your test name, this could be as per your easy and convenience.

 

Next tag is class name tag, Here you will provide the package name.class name i.e your test class should follow your package name. suppose my package is tested and my class name is FirstTest then the value of this tag should be “test.FirstTest” like – <class name=”test.FirstTest” />

So this is the structure of our testng.xml file. Now you need to copy your testng.xml file and paste this in your project.

 

After paste, your testng.xml file your project structure will look like this.

Testng.xml file

 

As we have seen, We have two class files SampleTest.java and TestExecutionOrder.java file with the package  com.Seleniumbix.TestNG.

Now we are going to edit our testng.xml file as per our Test files. Download sample file from here!

Download this file pastes this in the notepad file and save this file with name testng.xml and paste it into your project.

 

So our sample file looks like –

<!DOCTYPE suite SYSTEM “http://testng.org/testng-1.0.dtd” >
  
<suite name=”SampleSuite” >
  <test name=”First Test” >
    <classes>
       <class name=”com.Seleniumbix.TestNG.SampleTest” />
    </classes>
  </test>
 
  <test name=”Second Test”>
    <classes>
      <class name=”com.Seleniumbix.TestNG.TestExecutionOrder”/>
    </classes>
  </test>
</suite>

 

Execute TestNG Test Suite

Now the question is, How can we execute our Test suite. It’s quite simple to execute the Test suite in TestNG.

We have already placed our testng.xml file in our project. To execute the test case we need to execute this testng.xml file.

  • Right-click on your testng.xml file.
  • Hover mouse on Run As… , You will get the option TestNG TestSuite. Click this. Now TestNG will read this file and execute your test suite.

Execute Test Case

 

Refresh your project and lets see the TestNG report. Remember that index.html file in test-output directory. Lets have a look on Test Report.

TestNG TestReport

 

You can compare this report with our above-explained testng.xml. So this is the way how can we create and execute the Test Suite in TestNG and get the attractive reports.

Please explore the HTML reports as well and get familiar with the reporting terminology as it is the crucial part in software Testing.

0 Comment

Leave a Reply