Package org.testng.internal
Class Invoker
- java.lang.Object
-
- org.testng.internal.Invoker
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Invoker.CanRunFromClassPredicate
(package private) static class
Invoker.FailureContext
(package private) static interface
Invoker.Predicate<K,T>
(package private) static class
Invoker.SameClassNamePredicate
private static class
Invoker.StatusHolder
-
Field Summary
Fields Modifier and Type Field Description private static Invoker.Predicate<ITestNGMethod,IClass>
CAN_RUN_FROM_CLASS
Predicate to filter methodsprivate IAnnotationFinder
m_annotationFinder
private java.util.Map<java.lang.String,java.lang.Boolean>
m_beforegroupsFailures
Group failures must be synced as the Invoker is accessed concurrentlyprivate java.util.Map<java.lang.Class<?>,java.util.Set<java.lang.Object>>
m_classInvocationResults
Class failures must be synced as the Invoker is accessed concurrentlyprivate java.util.List<IClassListener>
m_classListeners
private IConfiguration
m_configuration
private boolean
m_continueOnFailedConfiguration
private java.util.Collection<IDataProviderListener>
m_dataproviderListeners
private java.util.Collection<IInvokedMethodListener>
m_invokedMethodListeners
private java.util.Map<ITestNGMethod,java.util.Set<java.lang.Object>>
m_methodInvocationResults
Test methods whose configuration methods have failed.private ITestResultNotifier
m_notifier
private boolean
m_skipFailedInvocationCounts
private SuiteRunState
m_suiteState
private ITestContext
m_testContext
private static Invoker.Predicate<ITestNGMethod,IClass>
SAME_CLASS
Predicate to filter methods
-
Constructor Summary
Constructors Constructor Description Invoker(IConfiguration configuration, ITestContext testContext, ITestResultNotifier notifier, SuiteRunState state, boolean skipFailedInvocationCounts, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.List<IClassListener> classListeners, java.util.Collection<IDataProviderListener> dataProviderListeners)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
checkDependencies(ITestNGMethod testMethod, ITestNGMethod[] allTestMethods)
Checks to see of the test method has certain dependencies that prevents TestNG from executing itprivate boolean
classConfigurationFailed(java.lang.Class<?> cls, java.lang.Object instance)
private void
collectResults(ITestNGMethod testMethod, ITestResult result)
private IConfigurable
computeConfigurableInstance(ConstructorOrMethod method, java.lang.Object targetInstance)
private static java.lang.Object
computeInstance(java.lang.Object instance, java.lang.Object inst, ITestNGMethod tm)
private static int
computeTestStatusComparingTestResultAndStatusHolder(ITestResult testResult, Invoker.StatusHolder holder, boolean wasResultUnaltered)
private boolean
confInvocationPassed(ITestNGMethod method, ITestNGMethod currentTestMethod, IClass testClass, java.lang.Object instance)
private Invoker.StatusHolder
considerExceptions(ITestNGMethod tm, ITestResult testresult, ExpectedExceptionsHolder exceptionsHolder, Invoker.FailureContext failure)
private java.util.Set<java.lang.Object>
getInvocationResults(IClass testClass)
private void
handleConfigurationFailure(java.lang.Throwable ite, ITestNGMethod tm, ITestResult testResult, IConfigurationAnnotation annotation, ITestNGMethod currentTestMethod, java.lang.Object instance, XmlSuite suite)
private void
handleConfigurationSkip(ITestNGMethod tm, ITestResult testResult, IConfigurationAnnotation annotation, ITestNGMethod currentTestMethod, java.lang.Object instance, XmlSuite suite)
Marks the currentTestResult
as skipped and invokes the listeners.private void
handleException(java.lang.Throwable throwable, ITestNGMethod testMethod, ITestResult testResult, int failureCount)
An exception was thrown by the test, determine if this method should be marked as a failure or as failure_but_within_successPercentageprivate void
handleInvocationResults(ITestNGMethod testMethod, ITestResult testResult, Invoker.FailureContext failure, Invoker.StatusHolder holder, boolean wasResultUnaltered)
private boolean
hasConfigFailure(ITestNGMethod currentTestMethod)
private boolean
haveBeenRunSuccessfully(ITestNGMethod testMethod, ITestNGMethod[] methods)
private void
invokeAfterGroupsConfigurations(ITestNGMethod currentTestMethod, ConfigurationGroupMethods groupMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, java.lang.Object instance)
private void
invokeBeforeGroupsConfigurations(ITestNGMethod currentTestMethod, ConfigurationGroupMethods groupMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, java.lang.Object instance)
Filter all the beforeGroups methods and invoke only those that apply to the current test methodprivate void
invokeConfigurationMethod(java.lang.Object targetInstance, ITestNGMethod tm, java.lang.Object[] params, ITestResult testResult)
Effectively invokes a configuration method on all passed in instances.void
invokeConfigurations(IClass testClass, ITestNGMethod[] allMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, java.lang.Object[] parameterValues, java.lang.Object instance)
Invoke configuration methods if they belong to the same TestClass passed in parameter..private void
invokeConfigurations(IClass testClass, ITestNGMethod currentTestMethod, ITestNGMethod[] allMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, java.lang.Object[] parameterValues, java.lang.Object instance, ITestResult testMethodResult)
private ITestResult
invokeMethod(java.lang.Object instance, ITestNGMethod tm, java.lang.Object[] parameterValues, int parametersIndex, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, ITestClass testClass, ITestNGMethod[] beforeMethods, ITestNGMethod[] afterMethods, ConfigurationGroupMethods groupMethods, Invoker.FailureContext failureContext)
private java.util.List<ITestResult>
invokePooledTestMethods(ITestNGMethod testMethod, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> parameters, ConfigurationGroupMethods groupMethods, ITestContext testContext)
Invokes a method that has a specified threadPoolSize.(package private) ITestResult
invokeTestMethod(java.lang.Object instance, ITestNGMethod tm, java.lang.Object[] parameterValues, int parametersIndex, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, ITestClass testClass, ITestNGMethod[] beforeMethods, ITestNGMethod[] afterMethods, ConfigurationGroupMethods groupMethods, Invoker.FailureContext failureContext)
invokeTestMethods() eventually converge here to invoke a single @Test method.java.util.List<ITestResult>
invokeTestMethods(ITestNGMethod testMethod, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> testParameters, ConfigurationGroupMethods groupMethods, java.lang.Object instance, ITestContext testContext)
Invoke all the test methods.private boolean
isSkipExceptionAndSkip(java.lang.Throwable ite)
private java.util.Set<ITestResult>
keepSameInstances(ITestNGMethod method, java.util.Set<ITestResult> results)
private void
log(int level, java.lang.String s)
private boolean
noListenersPresent()
private void
recordConfigurationInvocationFailed(ITestNGMethod tm, IClass testClass, IConfigurationAnnotation annotation, ITestNGMethod currentTestMethod, java.lang.Object instance, XmlSuite suite)
Record internally the failure of a Configuration, so that we can determine later if @Test should be skipped.private ITestResult
registerSkippedTestResult(ITestNGMethod testMethod, java.lang.Object instance, long start, java.lang.Throwable throwable)
(package private) int
retryFailed(java.lang.Object instance, ITestNGMethod tm, XmlSuite suite, ITestClass testClass, ITestNGMethod[] beforeMethods, ITestNGMethod[] afterMethods, ConfigurationGroupMethods groupMethods, java.util.List<ITestResult> result, int failureCount, ITestContext testContext, java.util.Map<java.lang.String,java.lang.String> parameters, int parametersIndex)
private void
runConfigurationListeners(ITestResult tr, boolean before)
private void
runInvokedMethodListeners(InvokedMethodListenerMethod listenerMethod, IInvokedMethod invokedMethod, ITestResult testResult)
(package private) void
runTestListeners(ITestResult tr)
private java.util.List<ITestResult>
runWorkers(ITestNGMethod testMethod, java.util.List<IWorker<ITestNGMethod>> workers, int threadPoolSize, ConfigurationGroupMethods groupMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> parameters)
To reduce thread contention and also to correctly handle thread-confinement this method invokes the @BeforeGroups and @AfterGroups corresponding to the current @Test method.private void
setClassInvocationFailure(java.lang.Class<?> clazz, java.lang.Object instance)
private void
setMethodInvocationFailure(ITestNGMethod method, java.lang.Object instance)
private static void
setTestStatus(ITestResult result, int status)
private void
throwConfigurationFailure(ITestResult testResult, java.lang.Throwable ex)
-
-
-
Field Detail
-
m_testContext
private final ITestContext m_testContext
-
m_notifier
private final ITestResultNotifier m_notifier
-
m_annotationFinder
private final IAnnotationFinder m_annotationFinder
-
m_suiteState
private final SuiteRunState m_suiteState
-
m_skipFailedInvocationCounts
private final boolean m_skipFailedInvocationCounts
-
m_invokedMethodListeners
private final java.util.Collection<IInvokedMethodListener> m_invokedMethodListeners
-
m_continueOnFailedConfiguration
private final boolean m_continueOnFailedConfiguration
-
m_classListeners
private final java.util.List<IClassListener> m_classListeners
-
m_dataproviderListeners
private final java.util.Collection<IDataProviderListener> m_dataproviderListeners
-
m_beforegroupsFailures
private final java.util.Map<java.lang.String,java.lang.Boolean> m_beforegroupsFailures
Group failures must be synced as the Invoker is accessed concurrently
-
m_classInvocationResults
private final java.util.Map<java.lang.Class<?>,java.util.Set<java.lang.Object>> m_classInvocationResults
Class failures must be synced as the Invoker is accessed concurrently
-
m_methodInvocationResults
private final java.util.Map<ITestNGMethod,java.util.Set<java.lang.Object>> m_methodInvocationResults
Test methods whose configuration methods have failed.
-
m_configuration
private IConfiguration m_configuration
-
CAN_RUN_FROM_CLASS
private static final Invoker.Predicate<ITestNGMethod,IClass> CAN_RUN_FROM_CLASS
Predicate to filter methods
-
SAME_CLASS
private static final Invoker.Predicate<ITestNGMethod,IClass> SAME_CLASS
Predicate to filter methods
-
-
Constructor Detail
-
Invoker
public Invoker(IConfiguration configuration, ITestContext testContext, ITestResultNotifier notifier, SuiteRunState state, boolean skipFailedInvocationCounts, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.List<IClassListener> classListeners, java.util.Collection<IDataProviderListener> dataProviderListeners)
-
-
Method Detail
-
setClassInvocationFailure
private void setClassInvocationFailure(java.lang.Class<?> clazz, java.lang.Object instance)
-
setMethodInvocationFailure
private void setMethodInvocationFailure(ITestNGMethod method, java.lang.Object instance)
-
invokeConfigurations
public void invokeConfigurations(IClass testClass, ITestNGMethod[] allMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, java.lang.Object[] parameterValues, java.lang.Object instance)
Invoke configuration methods if they belong to the same TestClass passed in parameter.. TODO: Calculate ahead of time which methods should be invoked for each class. Might speed things up for users who invoke the same test class with different parameters in the same suite run. If instance is non-null, the configuration will be run on it. If it is null, the configuration methods will be run on all the instances retrieved from the ITestClass.- Specified by:
invokeConfigurations
in interfaceIInvoker
- Parameters:
testClass
- the class whose configuration methods must be run
-
invokeConfigurations
private void invokeConfigurations(IClass testClass, ITestNGMethod currentTestMethod, ITestNGMethod[] allMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, java.lang.Object[] parameterValues, java.lang.Object instance, ITestResult testMethodResult)
-
computeInstance
private static java.lang.Object computeInstance(java.lang.Object instance, java.lang.Object inst, ITestNGMethod tm)
-
handleConfigurationSkip
private void handleConfigurationSkip(ITestNGMethod tm, ITestResult testResult, IConfigurationAnnotation annotation, ITestNGMethod currentTestMethod, java.lang.Object instance, XmlSuite suite)
Marks the currentTestResult
as skipped and invokes the listeners.
-
handleConfigurationFailure
private void handleConfigurationFailure(java.lang.Throwable ite, ITestNGMethod tm, ITestResult testResult, IConfigurationAnnotation annotation, ITestNGMethod currentTestMethod, java.lang.Object instance, XmlSuite suite)
-
recordConfigurationInvocationFailed
private void recordConfigurationInvocationFailed(ITestNGMethod tm, IClass testClass, IConfigurationAnnotation annotation, ITestNGMethod currentTestMethod, java.lang.Object instance, XmlSuite suite)
Record internally the failure of a Configuration, so that we can determine later if @Test should be skipped.
-
classConfigurationFailed
private boolean classConfigurationFailed(java.lang.Class<?> cls, java.lang.Object instance)
- Returns:
- true if this class or a parent class failed to initialize.
-
confInvocationPassed
private boolean confInvocationPassed(ITestNGMethod method, ITestNGMethod currentTestMethod, IClass testClass, java.lang.Object instance)
- Returns:
- true if this class has successfully run all its @Configuration method or false if at least one of these methods failed.
-
hasConfigFailure
private boolean hasConfigFailure(ITestNGMethod currentTestMethod)
-
getInvocationResults
private java.util.Set<java.lang.Object> getInvocationResults(IClass testClass)
-
invokeConfigurationMethod
private void invokeConfigurationMethod(java.lang.Object targetInstance, ITestNGMethod tm, java.lang.Object[] params, ITestResult testResult) throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException
Effectively invokes a configuration method on all passed in instances.- Throws:
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException
-
computeConfigurableInstance
private IConfigurable computeConfigurableInstance(ConstructorOrMethod method, java.lang.Object targetInstance)
-
throwConfigurationFailure
private void throwConfigurationFailure(ITestResult testResult, java.lang.Throwable ex)
-
runInvokedMethodListeners
private void runInvokedMethodListeners(InvokedMethodListenerMethod listenerMethod, IInvokedMethod invokedMethod, ITestResult testResult)
-
noListenersPresent
private boolean noListenersPresent()
-
invokeMethod
private ITestResult invokeMethod(java.lang.Object instance, ITestNGMethod tm, java.lang.Object[] parameterValues, int parametersIndex, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, ITestClass testClass, ITestNGMethod[] beforeMethods, ITestNGMethod[] afterMethods, ConfigurationGroupMethods groupMethods, Invoker.FailureContext failureContext)
-
setTestStatus
private static void setTestStatus(ITestResult result, int status)
-
collectResults
private void collectResults(ITestNGMethod testMethod, ITestResult result)
-
invokeTestMethod
ITestResult invokeTestMethod(java.lang.Object instance, ITestNGMethod tm, java.lang.Object[] parameterValues, int parametersIndex, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, ITestClass testClass, ITestNGMethod[] beforeMethods, ITestNGMethod[] afterMethods, ConfigurationGroupMethods groupMethods, Invoker.FailureContext failureContext)
invokeTestMethods() eventually converge here to invoke a single @Test method. This method is responsible for actually invoking the method. It decides if the invocation must be done:- through an
IHookable
- directly (through reflection)
- in a separate thread (in case it needs to timeout)
- through an
-
invokeBeforeGroupsConfigurations
private void invokeBeforeGroupsConfigurations(ITestNGMethod currentTestMethod, ConfigurationGroupMethods groupMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, java.lang.Object instance)
Filter all the beforeGroups methods and invoke only those that apply to the current test method
-
invokeAfterGroupsConfigurations
private void invokeAfterGroupsConfigurations(ITestNGMethod currentTestMethod, ConfigurationGroupMethods groupMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> params, java.lang.Object instance)
-
retryFailed
int retryFailed(java.lang.Object instance, ITestNGMethod tm, XmlSuite suite, ITestClass testClass, ITestNGMethod[] beforeMethods, ITestNGMethod[] afterMethods, ConfigurationGroupMethods groupMethods, java.util.List<ITestResult> result, int failureCount, ITestContext testContext, java.util.Map<java.lang.String,java.lang.String> parameters, int parametersIndex)
-
invokeTestMethods
public java.util.List<ITestResult> invokeTestMethods(ITestNGMethod testMethod, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> testParameters, ConfigurationGroupMethods groupMethods, java.lang.Object instance, ITestContext testContext)
Invoke all the test methods. Note the plural: the method passed in parameter might be invoked several times if the test class it belongs to has more than one instance (i.e., if an @Factory method has been declared somewhere that returns several instances of this TestClass). If no @Factory method was specified, testMethod will only be invoked once. Note that this method also takes care of invoking the beforeTestMethod and afterTestMethod, if any. Note (alex): this method can be refactored to use a SingleTestMethodWorker that directly invokesinvokeTestMethod(Object, ITestNGMethod, Object[], int, XmlSuite, Map, ITestClass, ITestNGMethod[], ITestNGMethod[], ConfigurationGroupMethods, FailureContext)
and this would simplify the implementation (see how DataTestMethodWorker is used)- Specified by:
invokeTestMethods
in interfaceIInvoker
- Returns:
- a list containing the results of the test methods invocations
-
registerSkippedTestResult
private ITestResult registerSkippedTestResult(ITestNGMethod testMethod, java.lang.Object instance, long start, java.lang.Throwable throwable)
-
invokePooledTestMethods
private java.util.List<ITestResult> invokePooledTestMethods(ITestNGMethod testMethod, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> parameters, ConfigurationGroupMethods groupMethods, ITestContext testContext)
Invokes a method that has a specified threadPoolSize.
-
considerExceptions
private Invoker.StatusHolder considerExceptions(ITestNGMethod tm, ITestResult testresult, ExpectedExceptionsHolder exceptionsHolder, Invoker.FailureContext failure)
-
handleInvocationResults
private void handleInvocationResults(ITestNGMethod testMethod, ITestResult testResult, Invoker.FailureContext failure, Invoker.StatusHolder holder, boolean wasResultUnaltered)
-
computeTestStatusComparingTestResultAndStatusHolder
private static int computeTestStatusComparingTestResultAndStatusHolder(ITestResult testResult, Invoker.StatusHolder holder, boolean wasResultUnaltered)
-
isSkipExceptionAndSkip
private boolean isSkipExceptionAndSkip(java.lang.Throwable ite)
-
runWorkers
private java.util.List<ITestResult> runWorkers(ITestNGMethod testMethod, java.util.List<IWorker<ITestNGMethod>> workers, int threadPoolSize, ConfigurationGroupMethods groupMethods, XmlSuite suite, java.util.Map<java.lang.String,java.lang.String> parameters)
To reduce thread contention and also to correctly handle thread-confinement this method invokes the @BeforeGroups and @AfterGroups corresponding to the current @Test method.
-
checkDependencies
private java.lang.String checkDependencies(ITestNGMethod testMethod, ITestNGMethod[] allTestMethods)
Checks to see of the test method has certain dependencies that prevents TestNG from executing it- Parameters:
testMethod
- test method being checked for- Returns:
- error message or null if dependencies have been run successfully
-
keepSameInstances
private java.util.Set<ITestResult> keepSameInstances(ITestNGMethod method, java.util.Set<ITestResult> results)
- Returns:
- the test results that apply to one of the instances of the testMethod.
-
haveBeenRunSuccessfully
private boolean haveBeenRunSuccessfully(ITestNGMethod testMethod, ITestNGMethod[] methods)
- Returns:
- true if all the methods have been run successfully
-
handleException
private void handleException(java.lang.Throwable throwable, ITestNGMethod testMethod, ITestResult testResult, int failureCount)
An exception was thrown by the test, determine if this method should be marked as a failure or as failure_but_within_successPercentage
-
runConfigurationListeners
private void runConfigurationListeners(ITestResult tr, boolean before)
-
runTestListeners
void runTestListeners(ITestResult tr)
-
log
private void log(int level, java.lang.String s)
-
-