I m using Eclipse + Selenium WebDriver + TestNG
This is my class structure :
class1
{
@test (invocation count =4)
method1()
@test (invocation count =4)
Look up "dependsOnGroups
" in the documentation.
You can also use "priority" of TestNG as:
@Test(priority = -19)
public void testMethod1(){
//some code
}
@Test(priority = -20)
public void testMethod2(){
//some code
}
[Note: The priority for this test method. Lower priorities will be scheduled first]
So, in the above example testMethod2 will be executed first as -20 less than -19
You can visit for more details: http://testng.org/doc/documentation-main.html#annotations
Of course there is a lot of methods to make it. An Example:
import java.lang.reflect.Method;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
public class ABC {
@Test(invocationCount=12)
public void uno(){
System.out.println("UNO");
}
@AfterMethod()
public void sec(Method m){
if(m.getName().equals("uno"))
System.out.println("SEC");
}
}
And suite:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<test name="Test" parallel="none" >
<classes>
<class name="aaa.ABC">
<methods>
<include name="uno">
</methods>
</class>
</classes>
</test> <!-- Test -->
</suite>
Remeber, if you use dependsOnMethod
then thoes method will be executed after all invocation.
For example:
@Test(invocationCount=3)
public void uno(){
System.out.println("UNO");
}
@Test(dependsOnMethods={"uno"})
public void sec(){
System.out.println("SEC");
}
with:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<test name="Test" parallel="none" >
<classes>
<class name="aaa.ABC">
<methods>
<include name="uno"/>
<include name="sec"/>
</methods>
</class>
</classes>
</test> <!-- Test -->
</suite>
will give:
UNO
UNO
UNO
SEC
===============================================
Suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
And if you test your tests please use verbose ="3"
in suite conf. example:
<suite name="Suite" parallel="none" verbose="3">
Cause this is turning on full logs.