Saturday, March 22, 2014

XML Configuration For TestNG

Previously we know basic configuration of TestNG classes and various annotation and attributes.Here we learn how to configure a xml file for TestNG classes and it's various tags and attributes. Obviously some question in our mind

Q. Can I run test without using testng.xml file?
 Ans:- Well answer is yes, we can run. But once our test become larger and requires configuration of multiple test at one place, the best option is testng.xml.

Ok this is the time to know more about TestNG xml file.....

The simple testng.xml file will have following hierarchy

  •        The root tag of this file is <suite>.

  • o   <suite> tag can contain one or more <test> tags.
    §  <test> tag can contain one or more <classes>
    ·         <classes> tag can contain one or more <class> tags.
    o   <class> tag can contain one <methods> tags.
    §  <methods> tags contain one or more<include> or <exclude>
    §   <test> tag can contain one <groups> tag
    ·         <groups> tag contain <define>
    o   <define>tag contain one or more<include> tag
    ·         <groups> tag contain <run> tag
    o   <run>tag contain one or more<include> or <exclude> tag
    o   <suite> tag can contain one or more <groups> tags.
    §  <groups> tag contain <define>
    ·         <define>tag contain one or more<include> tag
    §  <groups> tag contain <run> tag
    ·         <run>tag contain one or more<include> or <exclude> tag 
    § <groups> tag contain <dependencies>
    ·   <dependencies> contains <group>tag
If <groups> tag under <test> tag then it is available for this test onlt but if it is on <suite> tag then it is applicable for all test.

Some attribute description:


Increaseing Verbose value generate more log.


Parametrized Test using @Parameters

    @Parameters({"paraTest"})
    @Test
    public void runMethodGP1(String a) {
            System.out.println("Invoked testString " + a);
        System.out.println("runMethodGP1()");
    }


    <test name="TestNGAnotationClass2" time-out="1" preserve-order="true" annotations="JDK">
        <parameter name="paraTest" value="Test Parameter">
        </parameter>
        <classes>
            <class name="excelfilereadapachepoi.TestBase">
            </class>
            <class name="excelfilereadapachepoi.TestNGAnotationClass1">
            </class>
        </classes>
    </test>


1 comment:

  1. Thanks Arjun . Its a wonderful tutorial . Nicely described in leman language.

    ReplyDelete