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    */
getRealClass()26   Class getRealClass();
27 
getTestClass()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    */
setTestClass(ITestClass cls)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
getMethod()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    */
getMethodName()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
getInstances()60   Object[] getInstances();
61 
getInstance()62   Object getInstance();
63 
64   /**
65    * Needed for serialization.
66    */
getInstanceHashCodes()67   long[] getInstanceHashCodes();
68 
69   /**
70    * @return The groups this method belongs to, possibly added to the groups
71    * declared on the class.
72    */
getGroups()73   String[] getGroups();
74 
75   /**
76    * @return The groups this method depends on, possibly added to the groups
77    * declared on the class.
78    */
getGroupsDependedUpon()79   String[] getGroupsDependedUpon();
80 
81   /**
82    * If a group was not found.
83    */
getMissingGroup()84   String getMissingGroup();
setMissingGroup(String group)85   public void setMissingGroup(String group);
86 
87   /**
88    * Before and After groups
89    */
getBeforeGroups()90   public String[] getBeforeGroups();
getAfterGroups()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    */
getMethodsDependedUpon()97   String[] getMethodsDependedUpon();
addMethodDependedUpon(String methodName)98   void addMethodDependedUpon(String methodName);
99 
100   /**
101    * @return true if this method was annotated with @Test
102    */
isTest()103   boolean isTest();
104 
105   /**
106    * @return true if this method was annotated with @Configuration
107    * and beforeTestMethod = true
108    */
isBeforeMethodConfiguration()109   boolean isBeforeMethodConfiguration();
110 
111   /**
112    * @return true if this method was annotated with @Configuration
113    * and beforeTestMethod = false
114    */
isAfterMethodConfiguration()115   boolean isAfterMethodConfiguration();
116 
117   /**
118    * @return true if this method was annotated with @Configuration
119    * and beforeClassMethod = true
120    */
isBeforeClassConfiguration()121   boolean isBeforeClassConfiguration();
122 
123   /**
124    * @return true if this method was annotated with @Configuration
125    * and beforeClassMethod = false
126    */
isAfterClassConfiguration()127   boolean isAfterClassConfiguration();
128 
129   /**
130    * @return true if this method was annotated with @Configuration
131    * and beforeSuite = true
132    */
isBeforeSuiteConfiguration()133   boolean isBeforeSuiteConfiguration();
134 
135   /**
136    * @return true if this method was annotated with @Configuration
137    * and afterSuite = true
138    */
isAfterSuiteConfiguration()139   boolean isAfterSuiteConfiguration();
140 
141   /**
142    * @return <tt>true</tt> if this method is a @BeforeTest (@Configuration beforeTest=true)
143    */
isBeforeTestConfiguration()144   boolean isBeforeTestConfiguration();
145 
146   /**
147    * @return <tt>true</tt> if this method is an @AfterTest (@Configuration afterTest=true)
148    */
isAfterTestConfiguration()149   boolean isAfterTestConfiguration();
150 
isBeforeGroupsConfiguration()151   boolean isBeforeGroupsConfiguration();
152 
isAfterGroupsConfiguration()153   boolean isAfterGroupsConfiguration();
154 
155   /**
156    * @return The timeout in milliseconds.
157    */
getTimeOut()158   long getTimeOut();
setTimeOut(long timeOut)159   void setTimeOut(long timeOut);
160 
161   /**
162    * @return the number of times this method needs to be invoked.
163    */
getInvocationCount()164   int getInvocationCount();
setInvocationCount(int count)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    */
getTotalInvocationCount()173   int getTotalInvocationCount();
174 
175   /**
176    * @return the success percentage for this method (between 0 and 100).
177    */
getSuccessPercentage()178   int getSuccessPercentage();
179 
180   /**
181    * @return The id of the thread this method was run in.
182    */
getId()183   String getId();
184 
setId(String id)185   void setId(String id);
186 
getDate()187   long getDate();
188 
setDate(long date)189   void setDate(long date);
190 
191   /**
192    * Returns if this ITestNGMethod can be invoked from within IClass.
193    */
canRunFromClass(IClass testClass)194   boolean canRunFromClass(IClass testClass);
195 
196   /**
197    * @return true if this method is alwaysRun=true
198    */
isAlwaysRun()199   boolean isAlwaysRun();
200 
201   /**
202    * @return the number of threads to be used when invoking the method on parallel
203    */
getThreadPoolSize()204   int getThreadPoolSize();
205 
setThreadPoolSize(int threadPoolSize)206   void setThreadPoolSize(int threadPoolSize);
207 
getEnabled()208   boolean getEnabled();
209 
getDescription()210   public String getDescription();
setDescription(String description)211   void setDescription(String description);
212 
incrementCurrentInvocationCount()213   public void incrementCurrentInvocationCount();
getCurrentInvocationCount()214   public int getCurrentInvocationCount();
setParameterInvocationCount(int n)215   public void setParameterInvocationCount(int n);
getParameterInvocationCount()216   public int getParameterInvocationCount();
217 
clone()218   public ITestNGMethod clone();
219 
getRetryAnalyzer()220   public IRetryAnalyzer getRetryAnalyzer();
setRetryAnalyzer(IRetryAnalyzer retryAnalyzer)221   public void setRetryAnalyzer(IRetryAnalyzer retryAnalyzer);
222 
skipFailedInvocations()223   public boolean skipFailedInvocations();
setSkipFailedInvocations(boolean skip)224   public void setSkipFailedInvocations(boolean skip);
225 
226   /**
227    * The time under which all invocationCount methods need to complete by.
228    */
getInvocationTimeOut()229   public long getInvocationTimeOut();
230 
ignoreMissingDependencies()231   public boolean ignoreMissingDependencies();
setIgnoreMissingDependencies(boolean ignore)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    */
getInvocationNumbers()240   public List<Integer> getInvocationNumbers();
setInvocationNumbers(List<Integer> numbers)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    */
addFailedInvocationNumber(int number)247   public void addFailedInvocationNumber(int number);
getFailedInvocationNumbers()248   public List<Integer> getFailedInvocationNumbers();
249 
250   /**
251    * The scheduling priority. Lower priorities get scheduled first.
252    */
getPriority()253   public int getPriority();
setPriority(int priority)254   public void setPriority(int priority);
255 
256   /**
257    * @return the XmlTest this method belongs to.
258    */
getXmlTest()259   public XmlTest getXmlTest();
260 
getConstructorOrMethod()261   ConstructorOrMethod getConstructorOrMethod();
262 
263   /**
264    * @return the parameters found in the include tag, if any
265    * @param test
266    */
findMethodParameters(XmlTest test)267   Map<String, String> findMethodParameters(XmlTest test);
268 }
269