testng的分析一

2024-04-19 14:18
文章标签 分析 testng

本文主要是介绍testng的分析一,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

运行的代码是 自己设置listener, test class 设置是.class, 看看这个是testng run的路线

	TestListenerAdapter testListenerAdapter = new TestListenerAdapter();TestNG testNG = new TestNG();testNG.setTestClasses(new Class[]{test2.class});testNG.addListener(testListenerAdapter);testNG.run();List<ITestResult> testresults =testListenerAdapter.getPassedTests();System.out.println(testresults.get(0).getStatus());

testNG.ru()
then we will enter TestNG 的方法,进入 这个方法之前,我们已经将testclass传入了testng对像,但是未设置testsuite。
问题,testclass什么时候会被testng使用,并且会传给什么对象去处理。

public void run() {initializeSuitesAndJarFile();initializeConfiguration();initializeDefaultListeners();initializeCommandLineSuites();initializeCommandLineSuitesParams();initializeCommandLineSuitesGroups();sanityCheck();List<ISuite> suiteRunners = null;runExecutionListeners(true /* start */);//// Regular mode//else if (m_masterfileName == null) {suiteRunners = runSuitesLocally();}//// Master mode//  

initializeSuitesAndJarFile() 主要是设置 m_jatPath ,m_suites.。 在我们的例子中,没有suite,也未设置jar path , 所以两个都是0.
initializeConfiguration()

  • Install the listeners found in ServiceLoader (or use the class
    loader for tests, if specified).
  • Install the listeners found in the suites
  • Install the method selectors ???
  • Find if we have an object factory
    下面是设置一些其他的
m_configuration.setAnnotationFinder(new JDK15AnnotationFinder(getAnnotationTransformer()));
m_configuration.setHookable(m_hookable);
m_configuration.setConfigurable(m_configurable);
m_configuration.setObjectFactory(factory);

接下来是进入runseiteslocally, 我们知道之前返回的m_suite是空的,至少在initialsuiteandjar时候是空的。

 public List<ISuite> runSuitesLocally() {SuiteRunnerMap suiteRunnerMap = new SuiteRunnerMap();if (m_suites.size() > 0) {if (m_suites.get(0).getVerbose() >= 2) {Version.displayBanner();}

运行到这里,我发现这个m_suites并不为空,说明前面那个步骤必然是将test.class加入了testsuite中。我们发现,执行到 initializeCommandLineSuitesParams();这时候 suite就不为0了,可见suute的初始化在这个函数中做掉了。

private void initializeCommandLineSuites() {if (m_commandLineTestClasses != null || m_commandLineMethods != null) {if (null != m_commandLineMethods) {m_cmdlineSuites = createCommandLineSuitesForMethods(m_commandLineMethods);}else {m_cmdlineSuites = createCommandLineSuitesForClasses(m_commandLineTestClasses);}for (XmlSuite s : m_cmdlineSuites) {for (XmlTest t : s.getTests()) {t.setPreserveOrder(m_preserveOrder ? "true " : "false");}m_suites.add(s);if (m_groupByInstances != null) {s.setGroupByInstances(m_groupByInstances);}}}}

发现,m_commandLineTestClasses 就是 com.test.test2, 因此会仅需执行,这里我们的m_commandLineMethods 是为null的,
所以最终会调用,
m_cmdlineSuites = createCommandLineSuitesForClasses(m_commandLineTestClasses);
接着会被m_suites加入到list中。

有了suite之后,我们再回到runsuitelocally()
加下来就是创建线程去run这些worker.

public List<ISuite> runSuitesLocally() {SuiteRunnerMap suiteRunnerMap = new SuiteRunnerMap();if (m_suites.size() > 0) {if (m_suites.get(0).getVerbose() >= 2) {Version.displayBanner();}// First initialize the suite runners to ensure there are no configuration issues.// Create a map with XmlSuite as key and corresponding SuiteRunner as valuefor (XmlSuite xmlSuite : m_suites) {createSuiteRunners(suiteRunnerMap, xmlSuite);}//// Run suites//if (m_suiteThreadPoolSize == 1 && !m_randomizeSuites) {// Single threaded and not randomized: run the suites in orderfor (XmlSuite xmlSuite : m_suites) {runSuitesSequentially(xmlSuite, suiteRunnerMap, getVerbose(xmlSuite),getDefaultSuiteName());}} else {// Multithreaded: generate a dynamic graph that stores the suite hierarchy. This is then// used to run related suites in specific order. Parent suites are run only// once all the child suites have completed executionDynamicGraph<ISuite> suiteGraph = new DynamicGraph<ISuite>();for (XmlSuite xmlSuite : m_suites) {populateSuiteGraph(suiteGraph, suiteRunnerMap, xmlSuite);}IThreadWorkerFactory<ISuite> factory = new SuiteWorkerFactory(suiteRunnerMap,0 /* verbose hasn't been set yet */, getDefaultSuiteName());GraphThreadPoolExecutor<ISuite> pooledExecutor =new GraphThreadPoolExecutor<ISuite>(suiteGraph, factory, m_suiteThreadPoolSize,m_suiteThreadPoolSize, Integer.MAX_VALUE, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());Utils.log("TestNG", 2, "Starting executor for all suites");// Run all suites in parallelpooledExecutor.run();try {pooledExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);pooledExecutor.shutdownNow();}catch (InterruptedException handled) {Thread.currentThread().interrupt();error("Error waiting for concurrent executors to finish " + handled.getMessage());}}}e//// Generate the suites report//return Lists.newArrayList(suiteRunnerMap.values());}

这篇关于testng的分析一的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/917779

相关文章

Android 缓存日志Logcat导出与分析最佳实践

《Android缓存日志Logcat导出与分析最佳实践》本文全面介绍AndroidLogcat缓存日志的导出与分析方法,涵盖按进程、缓冲区类型及日志级别过滤,自动化工具使用,常见问题解决方案和最佳实... 目录android 缓存日志(Logcat)导出与分析全攻略为什么要导出缓存日志?按需过滤导出1. 按

Linux中的HTTPS协议原理分析

《Linux中的HTTPS协议原理分析》文章解释了HTTPS的必要性:HTTP明文传输易被篡改和劫持,HTTPS通过非对称加密协商对称密钥、CA证书认证和混合加密机制,有效防范中间人攻击,保障通信安全... 目录一、什么是加密和解密?二、为什么需要加密?三、常见的加密方式3.1 对称加密3.2非对称加密四、

MySQL中读写分离方案对比分析与选型建议

《MySQL中读写分离方案对比分析与选型建议》MySQL读写分离是提升数据库可用性和性能的常见手段,本文将围绕现实生产环境中常见的几种读写分离模式进行系统对比,希望对大家有所帮助... 目录一、问题背景介绍二、多种解决方案对比2.1 原生mysql主从复制2.2 Proxy层中间件:ProxySQL2.3

python使用Akshare与Streamlit实现股票估值分析教程(图文代码)

《python使用Akshare与Streamlit实现股票估值分析教程(图文代码)》入职测试中的一道题,要求:从Akshare下载某一个股票近十年的财务报表包括,资产负债表,利润表,现金流量表,保存... 目录一、前言二、核心知识点梳理1、Akshare数据获取2、Pandas数据处理3、Matplotl

python panda库从基础到高级操作分析

《pythonpanda库从基础到高级操作分析》本文介绍了Pandas库的核心功能,包括处理结构化数据的Series和DataFrame数据结构,数据读取、清洗、分组聚合、合并、时间序列分析及大数据... 目录1. Pandas 概述2. 基本操作:数据读取与查看3. 索引操作:精准定位数据4. Group

MySQL中EXISTS与IN用法使用与对比分析

《MySQL中EXISTS与IN用法使用与对比分析》在MySQL中,EXISTS和IN都用于子查询中根据另一个查询的结果来过滤主查询的记录,本文将基于工作原理、效率和应用场景进行全面对比... 目录一、基本用法详解1. IN 运算符2. EXISTS 运算符二、EXISTS 与 IN 的选择策略三、性能对比

MySQL 内存使用率常用分析语句

《MySQL内存使用率常用分析语句》用户整理了MySQL内存占用过高的分析方法,涵盖操作系统层确认及数据库层bufferpool、内存模块差值、线程状态、performance_schema性能数据... 目录一、 OS层二、 DB层1. 全局情况2. 内存占js用详情最近连续遇到mysql内存占用过高导致

深度解析Nginx日志分析与499状态码问题解决

《深度解析Nginx日志分析与499状态码问题解决》在Web服务器运维和性能优化过程中,Nginx日志是排查问题的重要依据,本文将围绕Nginx日志分析、499状态码的成因、排查方法及解决方案展开讨论... 目录前言1. Nginx日志基础1.1 Nginx日志存放位置1.2 Nginx日志格式2. 499

Olingo分析和实践之EDM 辅助序列化器详解(最佳实践)

《Olingo分析和实践之EDM辅助序列化器详解(最佳实践)》EDM辅助序列化器是ApacheOlingoOData框架中无需完整EDM模型的智能序列化工具,通过运行时类型推断实现灵活数据转换,适用... 目录概念与定义什么是 EDM 辅助序列化器?核心概念设计目标核心特点1. EDM 信息可选2. 智能类

Olingo分析和实践之OData框架核心组件初始化(关键步骤)

《Olingo分析和实践之OData框架核心组件初始化(关键步骤)》ODataSpringBootService通过初始化OData实例和服务元数据,构建框架核心能力与数据模型结构,实现序列化、URI... 目录概述第一步:OData实例创建1.1 OData.newInstance() 详细分析1.1.1