package org.testng;

import org.testng.annotations.CustomAttribute;
import org.testng.internal.ClassHelper;
import org.testng.internal.ConstructorOrMethod;
import org.testng.internal.IParameterInfo;
import org.testng.internal.InstanceCreator;
import org.testng.xml.XmlTest;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

Describes a TestNG annotated method and the instance on which it will be invoked.

This interface is not meant to be implemented by users.

/** * Describes a TestNG annotated method and the instance on which it will be invoked. * * <p>This interface is not meant to be implemented by users. */
public interface ITestNGMethod extends Cloneable {
Returns:The real class on which this method was declared (can be different from getMethod().getDeclaringClass() if the test method was defined in a superclass).
/** * @return The real class on which this method was declared (can be different from * getMethod().getDeclaringClass() if the test method was defined in a superclass). */
Class getRealClass(); ITestClass getTestClass();
Sets the test class having this method. This is not necessarily the declaring class.
Params:
  • cls – The test class having this method.
/** * Sets the test class having this method. This is not necessarily the declaring class. * * @param cls The test class having this method. */
void setTestClass(ITestClass cls);
Returns the method name. This is needed for serialization because methods are not Serializable.
Returns:the method name.
/** * Returns the method name. This is needed for serialization because methods are not Serializable. * * @return the method name. */
String getMethodName(); Object getInstance();
Needed for serialization.
Returns:The hashcode of instances
/** * Needed for serialization. * * @return The hashcode of instances */
long[] getInstanceHashCodes();
Returns:The groups this method belongs to, possibly added to the groups declared on the class.
/** * @return The groups this method belongs to, possibly added to the groups declared on the class. */
String[] getGroups();
Returns:The groups this method depends on, possibly added to the groups declared on the class.
/** * @return The groups this method depends on, possibly added to the groups declared on the class. */
String[] getGroupsDependedUpon();
Returns:If a group was not found.
/** @return If a group was not found. */
String getMissingGroup(); void setMissingGroup(String group); String[] getBeforeGroups(); String[] getAfterGroups();
Returns:The methods this method depends on, possibly added to the methods declared on the class.
/** * @return The methods this method depends on, possibly added to the methods declared on the * class. */
String[] getMethodsDependedUpon(); void addMethodDependedUpon(String methodName);
Returns:true if this method was annotated with @Test
/** @return true if this method was annotated with @Test */
boolean isTest();
Returns:true if this method was annotated with @Configuration and beforeTestMethod = true
/** @return true if this method was annotated with @Configuration and beforeTestMethod = true */
boolean isBeforeMethodConfiguration();
Returns:true if this method was annotated with @Configuration and beforeTestMethod = false
/** @return true if this method was annotated with @Configuration and beforeTestMethod = false */
boolean isAfterMethodConfiguration();
Returns:true if this method was annotated with @Configuration and beforeClassMethod = true
/** @return true if this method was annotated with @Configuration and beforeClassMethod = true */
boolean isBeforeClassConfiguration();
Returns:true if this method was annotated with @Configuration and beforeClassMethod = false
/** @return true if this method was annotated with @Configuration and beforeClassMethod = false */
boolean isAfterClassConfiguration();
Returns:true if this method was annotated with @Configuration and beforeSuite = true
/** @return true if this method was annotated with @Configuration and beforeSuite = true */
boolean isBeforeSuiteConfiguration();
Returns:true if this method was annotated with @Configuration and afterSuite = true
/** @return true if this method was annotated with @Configuration and afterSuite = true */
boolean isAfterSuiteConfiguration();
Returns:true if this method is a @BeforeTest (@Configuration beforeTest=true)
/** @return <code>true</code> if this method is a @BeforeTest (@Configuration beforeTest=true) */
boolean isBeforeTestConfiguration();
Returns:true if this method is an @AfterTest (@Configuration afterTest=true)
/** @return <code>true</code> if this method is an @AfterTest (@Configuration afterTest=true) */
boolean isAfterTestConfiguration(); boolean isBeforeGroupsConfiguration(); boolean isAfterGroupsConfiguration(); default boolean hasBeforeGroupsConfiguration() { return false; } default boolean hasAfterGroupsConfiguration() { return false; }
Returns:The timeout in milliseconds.
/** @return The timeout in milliseconds. */
long getTimeOut(); void setTimeOut(long timeOut);
Returns:the number of times this method needs to be invoked.
/** @return the number of times this method needs to be invoked. */
int getInvocationCount(); void setInvocationCount(int count);
Returns:the success percentage for this method (between 0 and 100).
/** @return the success percentage for this method (between 0 and 100). */
int getSuccessPercentage();
Returns:The id of the thread this method was run in.
/** @return The id of the thread this method was run in. */
String getId(); void setId(String id); long getDate(); void setDate(long date);
Params:
  • testClass – The test class
Returns:true if this ITestNGMethod can be invoked from within IClass.
/** * @param testClass The test class * @return true if this ITestNGMethod can be invoked from within IClass. */
boolean canRunFromClass(IClass testClass);
Returns:true if this method is alwaysRun=true
/** @return true if this method is alwaysRun=true */
boolean isAlwaysRun();
Returns:the number of threads to be used when invoking the method on parallel
/** @return the number of threads to be used when invoking the method on parallel */
int getThreadPoolSize(); void setThreadPoolSize(int threadPoolSize); boolean getEnabled(); String getDescription(); void setDescription(String description); void incrementCurrentInvocationCount(); int getCurrentInvocationCount(); void setParameterInvocationCount(int n); int getParameterInvocationCount(); void setMoreInvocationChecker(Callable<Boolean> moreInvocationChecker); boolean hasMoreInvocation(); ITestNGMethod clone();
Deprecated:- This method stands deprecated as of TestNG 7.0.0. Please use getRetryAnalyzer(ITestResult) instead.
Returns:The retry analyzer
/** * @deprecated - This method stands deprecated as of TestNG 7.0.0. * Please use {@link #getRetryAnalyzer(ITestResult)} instead. * * @return The retry analyzer */
@Deprecated IRetryAnalyzer getRetryAnalyzer();
Params:
  • retryAnalyzer – The retry analyzer
Deprecated:- This method stands deprecated as of TestNG 7.0.0. Please use setRetryAnalyzerClass(Class<? extends IRetryAnalyzer>) instead.
/** * @deprecated - This method stands deprecated as of TestNG 7.0.0. * Please use {@link #setRetryAnalyzerClass(Class)} instead. * * @param retryAnalyzer The retry analyzer */
@Deprecated void setRetryAnalyzer(IRetryAnalyzer retryAnalyzer); default IRetryAnalyzer getRetryAnalyzer(ITestResult result) { return getRetryAnalyzer(); } default void setRetryAnalyzerClass(Class<? extends IRetryAnalyzer> clazz) { setRetryAnalyzer(InstanceCreator.newInstance(clazz)); } default Class<? extends IRetryAnalyzer> getRetryAnalyzerClass() { return getRetryAnalyzer().getClass(); } boolean skipFailedInvocations(); void setSkipFailedInvocations(boolean skip);
Returns:The time under which all invocationCount methods need to complete by.
/** @return The time under which all invocationCount methods need to complete by. */
long getInvocationTimeOut(); boolean ignoreMissingDependencies(); void setIgnoreMissingDependencies(boolean ignore);
Which invocation numbers of this method should be used (only applicable if it uses a data provider). If this value is an empty list, use all the values returned from the data provider. These values are read from the XML file in the <include invocationNumbers="..."> tag.
Returns:The list of invocation numbers
/** * Which invocation numbers of this method should be used (only applicable if it uses a data * provider). If this value is an empty list, use all the values returned from the data provider. * These values are read from the XML file in the <code>&lt;include invocationNumbers="..."&gt;</code> tag. * * @return The list of invocation numbers */
List<Integer> getInvocationNumbers(); void setInvocationNumbers(List<Integer> numbers);
The list of invocation numbers that failed, which is only applicable for methods that have a data provider.
Params:
  • number – The invocation number that failed
/** * The list of invocation numbers that failed, which is only applicable for methods that have a * data provider. * * @param number The invocation number that failed */
void addFailedInvocationNumber(int number); List<Integer> getFailedInvocationNumbers();
The scheduling priority. Lower priorities get scheduled first.
Returns:The priority value
/** * The scheduling priority. Lower priorities get scheduled first. * * @return The priority value */
int getPriority(); void setPriority(int priority); int getInterceptedPriority(); void setInterceptedPriority(int priority);
Returns:the XmlTest this method belongs to.
/** @return the XmlTest this method belongs to. */
XmlTest getXmlTest(); ConstructorOrMethod getConstructorOrMethod();
Params:
Returns:the parameters found in the include tag, if any
/** * @param test - The {@link XmlTest} object. * @return the parameters found in the include tag, if any */
Map<String, String> findMethodParameters(XmlTest test);
getRealClass().getName() + "." + getMethodName()
Returns:qualified name for this method
/** * getRealClass().getName() + "." + getMethodName() * * @return qualified name for this method */
String getQualifiedName(); default boolean isDataDriven() { return false; }
Returns:- A IParameterInfo object that represents details about the parameters associated with the factory method.
/** * @return - A {@link IParameterInfo} object that represents details about the parameters * associated with the factory method. */
default IParameterInfo getFactoryMethodParamsInfo() { return null; }
Returns:- An array of CustomAttribute that represents the custom attributes associated with a test.
/** * @return - An array of {@link CustomAttribute} that represents the custom attributes associated * with a test. */
default CustomAttribute[] getAttributes() { return new CustomAttribute[]{}; }
Returns:- An IDataProviderMethod for a data provider powered test method and null otherwise.
/** * @return - An {@link IDataProviderMethod} for a data provider powered test method and * <code>null</code> otherwise. */
default IDataProviderMethod getDataProviderMethod() { return null; } }