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
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>
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·
define>
o
<define>tag contain one or more<include> tag
· <groups> tag contain <run> tago
<run>tag contain one or more<include> or <exclude> tag
o <suite> tag can contain one or more <groups> tags.§
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
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>
Thanks Arjun . Its a wonderful tutorial . Nicely described in leman language.
ReplyDelete