简单介绍
Apache JMeter是一个开源、纯Java编写,设计来为应用程序进行功能行为测试以及性能衡量的软件。
Apache JMeter may be used to test performance both on static and dynamic resources, Web dynamic applications.
It can be used to simulate a heavy load on a server, group of servers, network or object to test its strength or to analyze overall performance under different load types.
Apache JMeter features include:
- Ability to load and performance test many different applications/server/protocol types:
- Web - HTTP, HTTPS (Java, NodeJS, PHP, ASP.NET, …)
- SOAP / REST Webservices
- FTP
- Database via JDBC
- LDAP
- Message-oriented middleware (MOM) via JMS
- Mail - SMTP(S), POP3(S) and IMAP(S)
- Native commands or shell scripts
- TCP
- Java Objects
- Full featured Test IDE that allows fast Test Plan recording (from Browsers or native applications), building and debugging.
- CLI mode (Command-line mode (previously called Non GUI) / headless mode) to load test from any Java compatible OS (Linux, Windows, Mac OSX, …)
- A complete and ready to present dynamic HTML report
- Easy correlation through ability to extract data from most popular response formats, HTML, JSON , XML or any textual format
- Complete portability and 100% Java purity.
- Full multi-threading framework allows concurrent sampling by many threads and simultaneous sampling of different functions by separate thread groups.
- Caching and offline analysis/replaying of test results.
-
Highly Extensible core:
- Pluggable Samplers allow unlimited testing capabilities.
- Scriptable Samplers (JSR223-compatible languages like Groovy and BeanShell)
- Several load statistics may be chosen with pluggable timers.
- Data analysis and visualization plugins allow great extensibility as well as personalization.
- Functions can be used to provide dynamic input to a test or provide data manipulation.
- Easy Continuous Integration through 3rd party Open Source libraries for Maven, Gradle and Jenkins.
简单示例:
下面进行压力测试,模拟100用户同时调用下的运行情况,由于此次关注点在如何使用JMeter,服务接口的内部实现就略过,可自主实现。
前期准备
-
准备好要测试的服务接口,此次测试地址如下,该接口有两个方法,接收一个整数:
接口方法
-
下载并运行JMeter:
jmeter下载地址
这里测试环境为windows,下载后解压后运行jmeter.bat
建立和测试计划
-
首先选择测试计划,添加线程组:
添加线程组
添加后进行配置:
image.png
这里配置100并发,只执行一次。 -
创建Http请求并配置:
image.png
下面配置的是调用/add/{num}使用路径变量形式的url,如果是不是路径参数的话,去掉url后面的${num},在下面Parameters页面添加名称为num的参数,值不用设置,同样使用随后我们创建的随机变量配置来生成即可。
image.png
-
添加随机变量生成配置
image.png

- 添加结果查看树

-
选中测试计划并执行后,可以到结果查看树查看执行情况:
image.png
这样一个简单的使用JMeter进行测试的例子就完成了。
网友评论