package org.testng.internal;
import static org.testng.internal.invokers.InvokedMethodListenerMethod.AFTER_INVOCATION;
import static org.testng.internal.invokers.InvokedMethodListenerMethod.BEFORE_INVOCATION;
import org.testng.IClass;
import org.testng.IConfigurable;
import org.testng.IConfigurationListener;
import org.testng.IConfigurationListener2;
import org.testng.IHookable;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.IRetryAnalyzer;
import org.testng.ITestClass;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.SkipException;
import org.testng.SuiteRunState;
import org.testng.TestException;
import org.testng.TestNGException;
import org.testng.annotations.IConfigurationAnnotation;
import org.testng.annotations.NoInjection;
import org.testng.collections.Lists;
import org.testng.collections.Maps;
import org.testng.internal.InvokeMethodRunnable.TestNGRuntimeException;
import org.testng.internal.ParameterHolder.ParameterOrigin;
import org.testng.internal.annotations.AnnotationHelper;
import org.testng.internal.annotations.IAnnotationFinder;
import org.testng.internal.annotations.Sets;
import org.testng.internal.invokers.InvokedMethodListenerInvoker;
import org.testng.internal.invokers.InvokedMethodListenerMethod;
import org.testng.internal.thread.ThreadExecutionException;
import org.testng.internal.thread.ThreadUtil;
import org.testng.internal.thread.graph.IWorker;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
/**
* This class is responsible for invoking methods:
* - test methods
* - configuration methods
* - possibly in a separate thread
* and then for notifying the result listeners.
*
* @author <a href="mailto:cedric@beust.com">Cedric Beust</a>
* @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>
*/
public class Invoker implements IInvoker {
private final ITestContext m_testContext;
private final ITestResultNotifier m_notifier;
private final IAnnotationFinder m_annotationFinder;
private final SuiteRunState m_suiteState;
private final boolean m_skipFailedInvocationCounts;
private final List<IInvokedMethodListener> m_invokedMethodListeners;
private final boolean m_continueOnFailedConfiguration;
/** Group failures must be synced as the Invoker is accessed concurrently */
private Map<String, Boolean> m_beforegroupsFailures = Maps.newHashtable();
/** Class failures must be synced as the Invoker is accessed concurrently */
private Map<Class<?>, Set<Object>> m_classInvocationResults = Maps.newHashtable();
/** Test methods whose configuration methods have failed. */
private Map<ITestNGMethod, Set<Object>> m_methodInvocationResults = Maps.newHashtable();
private IConfiguration m_configuration;
/** Predicate to filter methods */
private static Predicate<ITestNGMethod, IClass> CAN_RUN_FROM_CLASS = new CanRunFromClassPredicate();
/** Predicate to filter methods */
private static final Predicate<ITestNGMethod, IClass> SAME_CLASS = new SameClassNamePredicate();
private void setClassInvocationFailure(Class<?> clazz, Object instance) {
Set<Object> instances = m_classInvocationResults.get( clazz );
if (instances == null) {
instances = Sets.newHashSet();
m_classInvocationResults.put(clazz, instances);
}
instances.add(instance);
}
private void setMethodInvocationFailure(ITestNGMethod method, Object instance) {
Set<Object> instances = m_methodInvocationResults.get(method);
if (instances == null) {
instances = Sets.newHashSet();
m_methodInvocationResults.put(method, instances);
}
instances.add(getMethodInvocationToken(method, instance));
}
public Invoker(IConfiguration configuration,
ITestContext testContext,
ITestResultNotifier notifier,
SuiteRunState state,
boolean skipFailedInvocationCounts,
List<IInvokedMethodListener> invokedMethodListeners) {
m_configuration = configuration;
m_testContext= testContext;
m_suiteState= state;
m_notifier= notifier;
m_annotationFinder= configuration.getAnnotationFinder();
m_skipFailedInvocationCounts = skipFailedInvocationCounts;
m_invokedMethodListeners = invokedMethodListeners;
m_continueOnFailedConfiguration = XmlSuite.CONTINUE.equals(testContext.getSuite().getXmlSuite().getConfigFailurePolicy());
}
/**
* Invoke configuration methods if they belong to the same TestClass passed
* in parameter.. <p/>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.
*/
@Override
public void invokeConfigurations(IClass testClass,
ITestNGMethod[] allMethods,
XmlSuite suite,
Map<String, String> params,
Object[] parameterValues,
Object instance)
{
invokeConfigurations(testClass, null, allMethods, suite, params, parameterValues, instance,
null);
}
private void invokeConfigurations(IClass testClass,
ITestNGMethod currentTestMethod,
ITestNGMethod[] allMethods,
XmlSuite suite,
Map<String, String> params,
Object[] parameterValues,
Object instance,
ITestResult testMethodResult)
{
if(null == allMethods) {
log(5, "No configuration methods found");
return;
}
ITestNGMethod[] methods= filterMethods(testClass, allMethods, SAME_CLASS);
for(ITestNGMethod tm : methods) {
if(null == testClass) {
testClass= tm.getTestClass();
}
ITestResult testResult= new TestResult(testClass,
instance,
tm,
null,
System.currentTimeMillis(),
System.currentTimeMillis(),
m_testContext);
IConfigurationAnnotation configurationAnnotation= null;
try {
Object[] instances= tm.getInstances();
if (instances == null || instances.length == 0) {
instances = new Object[] { instance };
}
Class<?> objectClass= instances[0].getClass();
Method method= tm.getMethod();
// Only run the configuration if
// - the test is enabled and
// - the Configuration method belongs to the same class or a parent
if(MethodHelper.isEnabled(objectClass, m_annotationFinder)) {
configurationAnnotation = AnnotationHelper.findConfiguration(m_annotationFinder, method);
if (MethodHelper.isEnabled(configurationAnnotation)) {
boolean isClassConfiguration = isClassConfiguration(configurationAnnotation);
boolean isSuiteConfiguration = isSuiteConfiguration(configurationAnnotation);
boolean alwaysRun= isAlwaysRun(configurationAnnotation);
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
testng 6.8.8 源码及 jar包 (389个子文件)
testng-reports.css 5KB
testng.css 312B
testng-1.0.dtd 8KB
collapseall.gif 157B
header 740B
testng-1.0.dtd.html 9KB
testng-6.8.8.jar 817KB
Invoker.java 72KB
TestNG.java 59KB
TestRunner.java 52KB
TestNGAntTask.java 34KB
Assert.java 30KB
EmailableReporter2.java 30KB
Assertion.java 28KB
XmlSuite.java 28KB
SuiteHTMLReporter.java 26KB
Logger.java 25KB
XmlTest.java 24KB
TestNGContentHandler.java 24KB
Utils.java 24KB
ClassHelper.java 20KB
SuiteRunner.java 19KB
BaseTestMethod.java 19KB
JDK15TagFactory.java 18KB
EmailableReporter.java 17KB
Parameters.java 17KB
ConfigurationMethod.java 15KB
XMLSuiteResultWriter.java 14KB
MethodHelper.java 13KB
TestResultMessage.java 13KB
XDom.java 13KB
MethodInvocationHelper.java 12KB
AnnotationHelper.java 12KB
TestHTMLReporter.java 12KB
LaunchSuite.java 12KB
XmlMethodSelector.java 12KB
XMLStringBuffer.java 11KB
AssertJUnit.java 11KB
VerboseReporter.java 11KB
DomUtil.java 10KB
TestMethodWorker.java 10KB
PackageUtils.java 10KB
MethodGroupsHelper.java 10KB
XMLReporter.java 9KB
FileAssert.java 9KB
ArrayAsserts.java 9KB
JUnitReportReporter.java 9KB
JUnitXMLReporter.java 9KB
JUnitTestRunner.java 9KB
TestNGClassFinder.java 9KB
RemoteTestNG.java 9KB
Yaml.java 9KB
TestClass.java 9KB
MessageHelper.java 8KB
Graph.java 8KB
JDK15AnnotationFinder.java 8KB
TimeBombSkipException.java 8KB
TestNGMethodFinder.java 8KB
FailedReporter.java 8KB
XMLReporterConfig.java 8KB
XmlClass.java 8KB
Parser.java 7KB
NavigatorPanel.java 7KB
BaseMessageSender.java 7KB
JqReporter.java 7KB
AbstractRemoteTestRunnerClient.java 7KB
JUnit4TestRunner.java 7KB
TestResult.java 7KB
Model.java 7KB
ClonedMethod.java 7KB
ClassImpl.java 7KB
TestNGMethod.java 7KB
ITestNGMethod.java 7KB
CommandLineArgs.java 7KB
InvokedMethodListenerInvoker.java 6KB
ResultContentHandler.java 6KB
DynamicGraph.java 6KB
Test.java 6KB
JUnitMethodFinder.java 6KB
ThreadUtil.java 6KB
SuiteDispatcher.java 5KB
TestListenerAdapter.java 5KB
TextReporter.java 5KB
NoOpTestClass.java 5KB
MethodInheritance.java 5KB
TestAnnotation.java 5KB
TestMethodWithDataProviderMethodWorker.java 5KB
SuiteRunnerWorker.java 5KB
JUnitTestClass.java 5KB
FileStringBuffer.java 5KB
GraphThreadPoolExecutor.java 5KB
ConfigurationGroupMethods.java 5KB
Reporter.java 4KB
Configuration.java 4KB
XmlPackage.java 4KB
XmlInclude.java 4KB
StringMessageSender.java 4KB
XMLUtils.java 4KB
ITestClass.java 4KB
XmlMethodSelector.java 4KB
共 389 条
- 1
- 2
- 3
- 4
richardguo_gc
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 土壤湿度数据文件AMSR-E Aqua L2B Surface Soil Moisture, Ancillary.pdf
- 基于matlab实现图像的条形码识别程序(识别EAN13码),只要条形码的背景部分是纯色,程序就能有相当强的鲁棒性 .rar
- 基于matlab实现遗传算法的投影寻踪模型Matlab源码.rar
- 使用lvgl v9自带LVGLImage.py把png图片批量生成bin或c文件的bat脚本
- 电子dxp教学课件:认识印制线路板.ppt
- 基于Pytorch的多种卷积神经网络模型搭建功能实现
- 280256087383610OldRoll-v4.9.0.apk
- VisualSVN Repository Configurator(VisualSVN库配置器)远程管理版本仓库
- 农作物害虫识别分类数据集4183张7类别.7z
- jenkins管道的方式从gitlib拉去若依并构建成docker镜像,生成容器.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页