Few more @Test annotations
1. enable annotation
import org.testng.annotations.*;
/**
* TestNG enable Test
* @author Himanshu Bisht
*
*/
public class Testenable {
@Test(enabled=false)
public void enablefalse() {
System.out.println("Enable false, so this method will not be tested");
}
}
Result : This method will not be tested
2. priority annotation
import org.testng.annotations.*;
/**
* TestNG priority Test
* @author Himanshu Bisht
*
*/
public class Testpriority {
@Test(priority=2)
public void logout() {
System.out.println("Logout of app");
}
@Test(priority=1)
public void gotohomepage() {
System.out.println("Navigate to home page");
}
@Test(priority=0)
public void login() {
System.out.println("Login to app");
}
}
Result : Methods will be executed based on priority, where priority 0 is max.
3. timeout annotation
import org.testng.annotations.*;
/**
* TestNG TimeOut Test
* @author Himanshu Bisht
*
*/
public class TesttimeOut {
@Test(timeOut = 1000)
public void testtimeOut() {
while (true);
}
}
Result : Failure : Method did not finished in 1000ms
4. expectedExceptions annotation
import org.testng.annotations.*;
/**
* TestNG expectedExceptions Test
* @author Himanshu Bisht
*
*/
public class TestexpectedExceptions {
@Test(expectedExceptions = ArithmeticException.class)
public void divisionWithException() {
int i = 10/0;
}
}
Result : Pass as method throws expected exception
0 comments:
Post a Comment