Home | History | Annotate | Download | only in testng
      1 package org.testng;
      2 
      3 
      4 import org.testng.internal.ConstructorOrMethod;
      5 import org.testng.xml.XmlTest;
      6 
      7 import java.io.Serializable;
      8 import java.lang.reflect.Method;
      9 import java.util.List;
     10 import java.util.Map;
     11 
     12 /**
     13  * Describes a TestNG annotated method and the instance on which it will be invoked.
     14  *
     15  * This interface is not meant to be implemented by users.
     16  *
     17  * @author Cedric Beust, May 3, 2004
     18  */
     19 public interface ITestNGMethod extends Comparable, Serializable, Cloneable {
     20 
     21   /**
     22    * @return The real class on which this method was declared
     23    * (can be different from getMethod().getDeclaringClass() if
     24    * the test method was defined in a superclass).
     25    */
     26   Class getRealClass();
     27 
     28   ITestClass getTestClass();
     29 
     30   /**
     31    * Sets the test class having this method. This is not necessarily the declaring class.
     32    *
     33    * @param cls The test class having this method.
     34    */
     35   void setTestClass(ITestClass cls);
     36 
     37   /**
     38    * @return the corresponding Java test method.
     39    * @deprecated This method is deprecated and can now return null. Use
     40    * getConstructorOrMethod() instead.
     41    */
     42   @Deprecated
     43   Method getMethod();
     44 
     45   /**
     46    * Returns the method name. This is needed for serialization because
     47    * methods are not Serializable.
     48    * @return the method name.
     49    */
     50   String getMethodName();
     51 
     52   /**
     53    * @return All the instances the methods will be invoked upon.
     54    * This will typically be an array of one object in the absence
     55    * of an @Factory annotation.
     56    *
     57    * @deprecated Use getInstance().
     58    */
     59   @Deprecated
     60   Object[] getInstances();
     61 
     62   Object getInstance();
     63 
     64   /**
     65    * Needed for serialization.
     66    */
     67   long[] getInstanceHashCodes();
     68 
     69   /**
     70    * @return The groups this method belongs to, possibly added to the groups
     71    * declared on the class.
     72    */
     73   String[] getGroups();
     74 
     75   /**
     76    * @return The groups this method depends on, possibly added to the groups
     77    * declared on the class.
     78    */
     79   String[] getGroupsDependedUpon();
     80 
     81   /**
     82    * If a group was not found.
     83    */
     84   String getMissingGroup();
     85   public void setMissingGroup(String group);
     86 
     87   /**
     88    * Before and After groups
     89    */
     90   public String[] getBeforeGroups();
     91   public String[] getAfterGroups();
     92 
     93   /**
     94    * @return The methods  this method depends on, possibly added to the methods
     95    * declared on the class.
     96    */
     97   String[] getMethodsDependedUpon();
     98   void addMethodDependedUpon(String methodName);
     99 
    100   /**
    101    * @return true if this method was annotated with @Test
    102    */
    103   boolean isTest();
    104 
    105   /**
    106    * @return true if this method was annotated with @Configuration
    107    * and beforeTestMethod = true
    108    */
    109   boolean isBeforeMethodConfiguration();
    110 
    111   /**
    112    * @return true if this method was annotated with @Configuration
    113    * and beforeTestMethod = false
    114    */
    115   boolean isAfterMethodConfiguration();
    116 
    117   /**
    118    * @return true if this method was annotated with @Configuration
    119    * and beforeClassMethod = true
    120    */
    121   boolean isBeforeClassConfiguration();
    122 
    123   /**
    124    * @return true if this method was annotated with @Configuration
    125    * and beforeClassMethod = false
    126    */
    127   boolean isAfterClassConfiguration();
    128 
    129   /**
    130    * @return true if this method was annotated with @Configuration
    131    * and beforeSuite = true
    132    */
    133   boolean isBeforeSuiteConfiguration();
    134 
    135   /**
    136    * @return true if this method was annotated with @Configuration
    137    * and afterSuite = true
    138    */
    139   boolean isAfterSuiteConfiguration();
    140 
    141   /**
    142    * @return <tt>true</tt> if this method is a @BeforeTest (@Configuration beforeTest=true)
    143    */
    144   boolean isBeforeTestConfiguration();
    145 
    146   /**
    147    * @return <tt>true</tt> if this method is an @AfterTest (@Configuration afterTest=true)
    148    */
    149   boolean isAfterTestConfiguration();
    150 
    151   boolean isBeforeGroupsConfiguration();
    152 
    153   boolean isAfterGroupsConfiguration();
    154 
    155   /**
    156    * @return The timeout in milliseconds.
    157    */
    158   long getTimeOut();
    159   void setTimeOut(long timeOut);
    160 
    161   /**
    162    * @return the number of times this method needs to be invoked.
    163    */
    164   int getInvocationCount();
    165   void setInvocationCount(int count);
    166 
    167   /**
    168    * @return the total number of thimes this method needs to be invoked, including possible
    169    *         clones of this method - this is relevant when threadPoolSize is bigger than 1
    170    *         where each clone of this method is only invoked once individually, i.e.
    171    *         {@link org.testng.ITestNGMethod#getInvocationCount()} would always return 1.
    172    */
    173   int getTotalInvocationCount();
    174 
    175   /**
    176    * @return the success percentage for this method (between 0 and 100).
    177    */
    178   int getSuccessPercentage();
    179 
    180   /**
    181    * @return The id of the thread this method was run in.
    182    */
    183   String getId();
    184 
    185   void setId(String id);
    186 
    187   long getDate();
    188 
    189   void setDate(long date);
    190 
    191   /**
    192    * Returns if this ITestNGMethod can be invoked from within IClass.
    193    */
    194   boolean canRunFromClass(IClass testClass);
    195 
    196   /**
    197    * @return true if this method is alwaysRun=true
    198    */
    199   boolean isAlwaysRun();
    200 
    201   /**
    202    * @return the number of threads to be used when invoking the method on parallel
    203    */
    204   int getThreadPoolSize();
    205 
    206   void setThreadPoolSize(int threadPoolSize);
    207 
    208   boolean getEnabled();
    209 
    210   public String getDescription();
    211   void setDescription(String description);
    212 
    213   public void incrementCurrentInvocationCount();
    214   public int getCurrentInvocationCount();
    215   public void setParameterInvocationCount(int n);
    216   public int getParameterInvocationCount();
    217 
    218   public ITestNGMethod clone();
    219 
    220   public IRetryAnalyzer getRetryAnalyzer();
    221   public void setRetryAnalyzer(IRetryAnalyzer retryAnalyzer);
    222 
    223   public boolean skipFailedInvocations();
    224   public void setSkipFailedInvocations(boolean skip);
    225 
    226   /**
    227    * The time under which all invocationCount methods need to complete by.
    228    */
    229   public long getInvocationTimeOut();
    230 
    231   public boolean ignoreMissingDependencies();
    232   public void setIgnoreMissingDependencies(boolean ignore);
    233 
    234   /**
    235    * Which invocation numbers of this method should be used (only applicable
    236    * if it uses a data provider). If this value is an empty list, use all the values
    237    * returned from the data provider.  These values are read from the XML file in
    238    * the <include invocationNumbers="..."> tag.
    239    */
    240   public List<Integer> getInvocationNumbers();
    241   public void setInvocationNumbers(List<Integer> numbers);
    242 
    243   /**
    244    * The list of invocation numbers that failed, which is only applicable for
    245    * methods that have a data provider.
    246    */
    247   public void addFailedInvocationNumber(int number);
    248   public List<Integer> getFailedInvocationNumbers();
    249 
    250   /**
    251    * The scheduling priority. Lower priorities get scheduled first.
    252    */
    253   public int getPriority();
    254   public void setPriority(int priority);
    255 
    256   /**
    257    * @return the XmlTest this method belongs to.
    258    */
    259   public XmlTest getXmlTest();
    260 
    261   ConstructorOrMethod getConstructorOrMethod();
    262 
    263   /**
    264    * @return the parameters found in the include tag, if any
    265    * @param test
    266    */
    267   Map<String, String> findMethodParameters(XmlTest test);
    268 }
    269