Testng: Case1 ( (Priority 1) Tcase1 (System. .Println ) (Priority 0) Tcase2
Testng: Case1 ( (Priority 1) Tcase1 (System. .Println ) (Priority 0) Tcase2
Annotations: meta tag which gives information about the method placed next to it
Order of Annotation : -
@BeforeSuite
@ BeforeTest
@BeforeGroup
@BeforeClass
@BeforeMethod
@Test
@afterMethod
@AfterClass
@Aftergroup
@AfterTest
@AfterSuite
For this in front of test annotations we can set priority, lower the number means higher the priority
@test(priority=1)
@test(priority=2)
@Test(priority =1)
public void TCase1()
{
System.out.println("This is Case1");
}
@Test(priority =0)
public void TCase2()
{
System.out.println("This is Case2");
}
2 Create Testng.xml
</suite>
Inside test, we must defile all classes that belongs to particular test
<suite name="MyAppName">
<test name="Test1">
<classes>
<class name="org.nitin.Case1"/>
</classes>
</test>
</suite>
Note : A basic set of xml is ready, which can be run, here we can execute whatever the number
of cases we want to execute
3 Update textng.xml in such a way that I want to include only few @test out of all existing @tests in
class
Inside class, add <methods> tag, inside method, use <include> tag, in include pass name of test
<suite name="MyAppName">
<test name="Test1">
<classes>
<class name="org.nitin.Case1">
<methods>
<include name="TCase2"/>
</methods>
</class>
</classes>
</test>
</suite>
*** Same way we can use exclude test, by which we can decide which @test, we
want to exclude
@Test(groups={"Smoke","Sanity"})
public void TCase1()
{
System.out.println("This is Case1");
}
@Test(groups={"sanity"})
public void TCase2()
{
System.out.println("This is Case2");
}
Now in testng.xml, create a groups tag inside test tag, inside group
create a run, inside run, use include and give name of test
<suite name="MyAppName">
<test name="Test1">
<classes>
<class name="org.nitin.Case1">
</class>
</classes>
<groups >
<run>
<include name="Smoke"/>
</run>
</groups>
</test>
</suite>
package org.nitin;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
Testng.xml
<suite name="MyAppName">
<test name="Test1">
<classes>
<class name="org.nitin.Case1">
</class>
</classes>
<groups>
<run>
<include name="Smoke"/>
</run>
</groups>
</test>
</suite>