What is the difference between prioritize and dependsMethos

Hi Lakshya,

I am just confused about what is the difference between Prioritize and Dependsmethods attribute of Test annotation. Because what i am thinking that we can use either one of them for executing the test cases in a sequence.

Please suggest.

mohitit09 Default Asked on January 12, 2015 in Selenium WebDriver.
Add Comment
2 Answer(s)

TestNG Test Case Priority

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.
TestNG 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.

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.

TestNG Priority

dependsOnMethod

import org.testng.annotations.Test;

 

pradhakrishna284 Train Answered on January 22, 2015.
Add Comment

dependsOnMethod

 

In the above scenario, the “sendEmail” method gets executed only when “login” method is executed and passed. If “login” method fails then the “sendEmail” method is skipped, i.e. it is not executed and is NOT marked as failed.

pradhakrishna284 Train Answered on January 22, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.