周燕 肖玉 王智超



摘 要: 许多应用系统功能日益复杂,JMeter已有的功能组件时常无法满足测试需求。文章根据JMeter的开源特性,对其进行二次开发,通过自定义函数扩展其已有功能;详细介绍JMeter自定义函数开发的原理和流程并给出关键代码的实现过程;结合WebTours系统,将完成的自定义函数应用于具体的测试场景。帮助测试人员快速掌握自定义函数的实现与应用,实现定制化的功能,以满足个性化的测试需求。
关键词: JMeter; 开源; 自定义函数; 二次开发
中图分类号:TP31 文献标识码:A 文章编号:1006-8228(2023)02-135-04
Abstract: Many application systems have increasingly complex functions, and JMeter's existing functional components often fail to meet the test requirements. In this paper, based on the open source characteristics of JMeter, we perform secondary development and extend its existing functions through custom functions. The principle and flow of JMeter custom function development are introduced in detail, and the realization process of key code is given. Combined with the WebTours system, the completed custom functions are applied to specific test scenarios. It helps testers to quickly master the implementation and application of custom functions, realize customized functions, and meet personalized test requirements.
Key words: JMeter; open source; custom functions; secondary development
0 引言
JMeter是Apache基金會旗下一款优秀的性能测试和接口测试工具,已经被越来越多的公司所采用。与同类的性能测试工具LoadRunner、接口测试工Postman相比,其优点是100%纯Java[1]开发且开源、有较强的扩展性。它拥有丰富的插件、元件和函数等功能来满足各种测试需求。但随着应用系统业务逻辑复杂性的大幅提升,系统的功能也日益个性化,测试工作的难度陡增。JMeter已有功能更多的是针对一些通用性的功能而开发,很难满足这种个性化的需求。得益于其开源特性,JMeter拥有其他测试工具所没有的可灵活扩展性,用户可根据实际功能需求和测试场景,对JMeter做二次开发[2],实现个性化的测试需求。JMeter二次开发一般分为三类情况:自定义组件、自定义请求和自定义函数。在JMeter中通过函数可以灵活的获取动态变化的值,代替录制脚本时所设置的固定值,对脚本进行参数化,使整个测试过程更加贴近实际的应用场景。……