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