TestNG Tutorial and Example – Suite Test

A test suite is a collection of test cases that are intended to test a behaviour or set of behaviours of software program.

In TestNG, we cannot define a suite in testing source code, for better, it is represented by one XML file, because suite is the feature of execution, this also allows flexible configuration of the tests to be run and keep no change to code base once suite is changed. A suite can contain one or more tests and is defined by the <suite> tag.

We created the following example suite Suite1 which includes SimpleTest1 and SimpleTest2, the several test cases are bundled so will be executed together.

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

<suite name="Suite1" verbose="1" >
  <test name="SimpleTest1" >
    <classes>
      <class name="tutorialSimpleTest1" />
    </classes>
  </test>

  <test name="SimpleTest2">
    <classes>
      <class name="ParameterSample"/>
      <class name="ParameterTest"/>
    </classes>
  </test>
</suite>

In TestNG runing command line, we can specific a suite name to be ran by using option -suitename.
Example:

java org.testng.TestNG testng.xml -suitename Suite1

Note if you annotated methods with @BeforeSuite or @AfterSuite in this test suite, the methods will be run before or after all tests in this suite.

 

Оцените статью
ASJAVA.COM
Добавить комментарий

Your email address will not be published. Required fields are marked *

*

code

  1. faizal

    Hi,

    I am using testNg . And i have created a testng.xml file which is working fine from eclipse. please guide me how to run it from command prompt.

    I dont know from which folder we need to run the command .

    java org.testng.TestNG testng.xml -suitename Suite1

    Ответить
    1. admin автор

      You need to set classpath both for testng.jar and your code jar.
      then cd /location to your suite xml file: java org.testng.TestNG testng.xml -suitename Suite1

      Ответить
  2. Ahmad

    Hi can you please make a complete example on how using XML file with TestNG in details accompanied with images?

    Ответить
    1. Sudheer

      Hi
      For Example you created a project in eclipse Say “Test1″, and created a java class say NewTest.java in a package “com”. It will be like
      Test1
      src
      com
      NewTest.java

      The location of NewTest.java is “D:\WorkSpace\Test1\src\com\NewTest.java” in its local system (Lets assume)

      In order to execute it through command prompt
      STEP1:- Go To D:\WorkSpace\Test1\src>
      execute the following command to compile the java class
      javac com\NewTest.java

      STEP2:-
      Before going to step2, you need to download the jars
      1) testng-6.8.jar
      2) reportng-1.1.4.jar
      3) velocity-dep-1.4.jar
      4) guice-3.0.jar
      and save it in your local system. In my system I saved at location
      D:\TESTNG_Sample_Executable\TESTNG\lib
      Note:- We will be using above location for Step2.

      STEP2:- Go to D:\WorkSpace\Test1\src>
      execute the following command

      java -cp “.;D:\TESTNG_Sample_Executable\TESTNG\lib\testng-6.8.jar;D:\TESTNG_Sample_Executable\TESTNG\lib\reportng-1.1.4.jar;D:\TESTNG_Sample_Executable\TESTNG\lib\velocity-dep-1.4.jar;D:\TESTNG_Sample_Executable\TESTNG\lib\guice-3.0.jar” org.testng.TestNG testng.xml

      This will show you the status of your test cases.

      Please let me know if you still faces any problem

      Thanks
      Sudheer

      Ответить