PRIORITY IN TestNG : In TestNG
"Priority" is used to schedule the test cases. When there are
multiple test cases, we want to execute test cases in order. Like First we need
to execute a test case "Registration" before login.
In order to
achive, we use need to add annotation as @Test(priority=??). The default value
will be zero for priority.
If you don't
mention the priority, it will take all the test cases as "priority=0"
and execute.
If we define
priority as "priority=", these test cases will get executed only when
all the test cases which don't have any priority as the default priority will
be set to "priority=0"
The below screen
shot shows a test cases which are not defined with any priority.
The below
examples shows using the priority for test cases.
As we have
not defined the priority for testcase "Registration", it will get
executed first and then the other testcases based on priority.
import org.testng.annotations.Test;
public
class testNGPriorityExample {
@Test
public
void
registerAccount()
{
System.
out.println(
"First register your account");
}
@Test(priority=
2)
public
void
sendEmail()
{
System.
out.println(
"Send email after login");
}
@Test(priority=
1)
public
void
login()
{
System.
out.println(
"Login to the account after registration");
}
}
The below
images shows the executed result of the above program.
'Registration'
test case will get executed first as we normally do that before login to any of
the application.
No comments:
Post a Comment