A distributed user-friendly Dubbo interface testing platform
-
摘要: 随着互联网金融的发展,金融业务变得更加复杂,产品功能迭代更加快速.为了支持业务的发展,金融应用开始进行支持Dubbo协议的开发.现有的接口测试框架和工具在支持Dubbo协议、多人协作及测试用例维护及数据分析上都存在问题:首先,没有很好的工具支持Dubbo协议的测试,已有的Dubbo测试框架无法很好地推广;其次,复杂业务会涉及多个应用,目前的框架很少考虑多系统间的自动化配合;再次,单机版自动化测试工具或纯编码方式的自动化测试框架不利于多人协作编写自动化测试用例及脚本的维护;最后,数据分析一般是查看单个子系统测试用例的执行结果,无法很好地对数据进行全局分析.为了更好地管理大批量用例及支持多子系统版本迭代,在已有老框架基础上,使用分布式技术设计并实现了一个灵活的可视化的Dubbo接口自动化测试平台:基于界面操作,提供基于可视化的数据驱动及关键字驱动方式,支持编写复杂测试用例,并基于接口解析的方式,自动生成测试用例.详细表述了可视化的Dubbo接口测试平台的架构、用例管理及用例执行;展示了新平台与老框架的耗时对比、用例增长对比和新平台日常自动化执行情况.Abstract: With the development of online finance, the financial business has become increasingly complex and product iterations have become more frequent. Financial applications have started to use the Dubbo protocol for programming to support this prosperous business. There are some problems, however, in supporting testing of the Dubbo protocol, multiplayer collaboration, maintenance, and data analysis with the current testing tools. First, these tools can only be used to test the Dubbo protocol and the Dubbo testing framework that exists at present is difficult to promote. Second, complex businesses involve multiple applications; the current system does not consider automated collaboration among multiple systems. Third, single-machine automatic testing tools or coded automatic testing frames are not good for multiplayer collaboration in writing automatic test cases and maintenance. Finally, data analysis is usually the execution result when reviewing single-system test cases so it cannot provide a holistic analysis of data. In order to manage a large quantity test cases and support multi-system upgrades, this paper uses distribution technology to design and implement a flexible and visible Dubbo automatic testing platform with the existing testing framework. Based on an interface application, the paper provides visible data-driven and keyword-driven methods and supports the programming of complex test cases. It can also generate the interfaces that you need to test and can generate test cases according to them automatically. This paper describes the architecture of this user-friendly Dubbo testing platform and the management of test cases and execution in a detailed way. Lastly, it shows a comparison of cost vs. time and a comparison of automated test case growth between the old framework and the daily execution results of the new platform's automation testing.
-
表 1 用例关键字
Tab. 1 Keywords of cases
用例关键字 说明 $app.config(key) 获取配置项key的值 $app.globalConfig(key) 获取系统级配置项key的值 $app.request.key 获取请求报文中key的值 $app.content.key 获取返回报文中key的值 $app.addContext(key, value) 把key及value值加入上下文 $app.getContext(key) 通过key, 把对应的value值从上下文中取出 dataSet[key] 通过key, 取出数据集中对应的value值 $app.assert(key, value) 通过key, 验证期望的是value值 算法1 负载均衡规则算法 输入:负载均衡对象ILoadBalancer lb 输出:选取的执行server 1: hashKey $\leftarrow $从线程上下文中获取子系统对应版本的唯一标志appId 2: while true 3: do servers.clear(); //servers保存负载均衡需要选取的work(server) 4: if server = null且count++ $ < $ 10 then //try ten times 5: reachableServers $\leftarrow $ lb.getReachableServers(); //reachableServers's 6: type is List which saves the normal work instances 7: allServers $\leftarrow $ lb.getAllServers(); //通过负载均衡对象获取所有servers 8: for server1 in allServers 9: do o $\leftarrow $从缓存中获取不满足要求的server列表 10: If o=null then 11: servers.add(server1);//把满足要求的server1存入servers 12: end 13: upCount $\leftarrow $ reachableServers.size(); //可以使用的servers大小 14: serverCount $\leftarrow $ servers.size(); 15: if upCount!=0且serverCount!= 0 then 16: servers.sort(); //根据appId对servers进行排序 17: index $\leftarrow $ Integer.valueOf(HashKey) % serverCount; //选择server 18: server $\leftarrow $ servers.get(index); 19: if server = null then 20: Thread.yield(); 21: elseif 22: 再次从缓存中获取不满足要求的servers列表!=null 23: Continue; 24: if server.isAlive()且server.isReadyToServe() then //判断server可用 25: return server; 26: else server $\leftarrow $ null; 27: else continue; 28: else return null; 29: end 表 2 新旧耗时对比数据
Tab. 2 Cost vs. time comparison between the old and new framework
老框架 新平台 准备测试环境 4 h/人 0 准备测试用例(单步骤) 3 min/个 1 min/个 执行测试用例(单步骤) 1 min/个 0.3 s/个 准备测试用例(复杂场景) 20 min/个 3 min/个 多环境适配(单步骤) 4 min/个 1.3 min/个 多环境适配(复杂场景) 20 min/个 3 min/个 分析测试结果 2 h/子系统 1 h/子系统 汇总 6.8 h 1.2 h 表 3 用例日常执行数据
Tab. 3 Execution records of daily cases
子系统-版本 TC总数 TC成功率/% 步骤总数 行覆盖率/% 执行耗时 1-20180510 1 267 64.40 6852 46.22 81 min 2-20180510 773 96.64 1 744 39.89 8 min35 s 3-20180510 773 66.24 1 422 11.36 8 min20 s 4-20180510 700 76.88 2 122 22.32 37 min16 s 5-20180510 550 84.24 563 31.95 7 min42 s 6-20180510 504 93.45 523 35.24 1 min43 s 7-20180510 451 94.92 696 45.22 6 min58 s 8-20180510 419 71.26 432 25.16 7 min17 s 9-20180510 378 88.62 2 203 27.53 23 min49 s 10-20180510 336 97.24 420 47.90 2 min29 s -
[1] 席涛, 郑贤强.大数据时代互联网产品的迭代创新设计方法研究[J].包装工程, 2016, 37(8):1-4. http://www.wanfangdata.com.cn/details/detail.do?_type=perio&id=bzgc201608001 [2] 周永红, 张彦祥.金融软件的自动化测试探索与创新之路[J].中国金融电脑, 2018(1):64-68. doi: 10.3969/j.issn.1001-0734.2018.01.015 [3] TAY B H, ANANDA A L. A survey of remote procedure calls[J]. ACM SIGOPS Operating Systems Review, 1990, 24(3):68-79. doi: 10.1145/382244 [4] APACHE SOFTWARE FOUNDATION. Apache Dubbo[OB/OL].[2018-06-20]. http://Dubbo.apache.org/. [5] SoapUI. Available[EB/OL]. (2017-12-04)[2018-07-01]. https://www.soapui.org/. [6] SOAP. WWW, Service Architecture, Soap[EB/OL]. (2016-07-17)[2018-07-01]. https://www.service-architecture.com/articles/web-services/soap.html. [7] 杨超.基于分布式服务框架Dubbo的集群式服务器的研究与实现[D].北京: 北京邮电大学, 2017. http://cdmd.cnki.com.cn/Article/CDMD-10013-1017292258.htm [8] Apache JMeterTM. The Apache Software Foundation[EB/OL]. (2016-07-17)[2018-07-01]. http://jmeter.apache.org/index.html. [9] MICRO FOCUS. LoadRunner Load Testing Software[EB/OL]. (2017-08-30)[2018-07-01]. https://www.microfocus.com/en-us/products/loadrunner-load-testing/overview. [10] NIELSEN H F, GETTYS J, BAIRD-SMITH A, et al. Network performance effects of HTTP/1.1[J]. ACM Sigcomm Computer Communication Review, 1997, 27(4):155-166. doi: 10.1145/263109 [11] MENG F Y. Phoenix Framewor[EB/OL]. (2016-07-17)[2018-07-01]. http://www.cewan.la/. [12] SHANG Y, ZHANG X L, FENG Y B, et al. Research and application of automated testing tool based on STAF[C]//Proceedings of the 2nd International Conference on Computer Science and Electronics Engineering. Paris: Atlantis Press, 2013: 2336-2339. [13] SOURCE FORGE. Software Testing Automation Framework (STAF)[EB/OL]. (2016-12-31)[2018-07-01]. http://staf.sourceforge.net/index.php. [14] HE Z H, ZHANG X, ZHU X Y. Design and implementation of automation testing framework based on keyword driven[J]. Applied Mechanics and Materials, 2014, 602/603/604/605:2142-2146. http://www.wanfangdata.com.cn/details/detail.do?_type=perio&id=10.4028/www.scientific.net/AMM.602-605.2142 [15] ECMA INTERNATIONAL. The JSON Data Interchange Syntax[EB/OL]. (2016-12-31)[2018-07-01]. http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf. [16] JOY J, SINGH D P. A generic framework design to enhance capabilities of an enterprise test automation framework[C]//International Conference on Applied and Theoretical Computing and Communication Technology. IEEE, 2016: 207-212. [17] GRIFFIN L, RYAN K, DE LEASTAR E, et al. Scaling instant messaging communiction services: A comparison of blocking and non-blocking techniques[C]//2011 IEEE Symposium on Computers and Communications. IEEE, 2011: 550-557. [18] JUNQUEIRA F, REED B. ZooKeeper: Distributed Process Coordination[M].[S.l]: O'Reilly Media, Inc. 2013. [19] BURROWS M. The Chubby lock service for loosely-coupled distributed systems[C]//OSDI'06: 7th USENIX Symposium on Operating Systems Design and Implementation. USENIX Association, 2006: 335-350. [20] MAVEN. The Apache Software Foundation[EB/OL].[2018-07-01]. https://maven.apache.org/what-is-maven.html. [21] TestNG. The Apache Software Foundation[EB/OL]. (2017-12-19)[2018-07-01]. http://testng.org/doc/documentation-main.html. [22] REESE W. Nginx:The high-performance web server and reverse proxy[J]. Linux Journal, 2008, 2008(173):2. http://d.old.wanfangdata.com.cn/Periodical/jsjxtyy201306048 [23] GITHUB. Netflix, Eureka[EB/OL].[2018-07-01]. https://github.com/Netflix/eureka. [24] EHCACHE. Software AG USA[EB/OL]. (2017-05-25)[2018-07-01]. http://www.ehcache.org/about/index.html. [25] REDIS. Redis Labs[EB/OL]. (2017-07-00)[2018-07-01]. https://redis.io/topics/introduction. [26] Netflix, Ribbon[EB/OL]. (2018-04-28)[2018-07-01]. https://github.com/Netflix/ribbon.