Searching...
Tuesday, 30 July 2013

alwaysRun annotation

@Test Annotation: alwaysRun

1.       alwaysRun annotation : Lets explain alwaysRun with an example

import org.testng.annotations.*;
/**
 * TestNG always run
 * @author himanshu bisht
 *
 */
public class ExampleTestNGT {
        @Test
        public void methodfail() { 
          System.out.println("Fail Method");
        }
       
        @Test(dependsOnMethods={"methodfail"}, alwaysRun=true) 
        public void alwaysruntrue() { 
          System.out.println("Always run is true");
        }
}

In this case alwaysRuntrue method will always run even if methodfail is pass or fail





21 comments:

  1. Instead of using alwaysRun why can't we delete dependsOnMethods. Both will have the same result

    ReplyDelete
  2. Ritesh gupta - lets assume a scenario where method B dependsOn method A. For e.g. A calculates how much loan will be approved for an individual based on various inputs like salary, saveings, Debt etc. So B has to depend on A. we cannot omit this. But there can be a situation that A failed for some reason and hence no value can be passed to B for the approved loan amount. Now we would not want the B never runs too. In B i could have a logic that if we didnt get value from A, then do something else - may be trigger an email to the case handler, or take the loan application to a specific queue etc. So in the above scenario I will need both dependsOn as well as alwaysRun. I hop that helpss

    ReplyDelete

 
Back to top!