文章目录
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/c0214c20358673cb6035b64429cd0717.jpeg)
前言
Gatling是一款基于Scala 开发的高性能服务器性能测试工具,它主要用于对服务器进行负载等测试,并分析和测量服务器的各种性能指标。目前仅支持http协议,可以用来测试web应用程序和RESTful服务。
除此之外它拥有以下特点:
- 支持Akka Actors 和 Async IO,从而能达到很高的性能
- 支持实时生成Html动态轻量报表,从而使报表更易阅读和进行数据分析
- 支持DSL脚本,从而使测试脚本更易开发与维护
- 支持录制并生成测试脚本,从而可以方便的生成测试脚本
- 支持导入HAR(Http Archive)并生成测试脚本
- 支持Maven,Eclipse,IntelliJ等,以便于开发
- 支持Jenkins,以便于进行持续集成
- 支持插件,从而可以扩展其功能,比如可以扩展对其他协议的支持
- 开源免费
依赖工具
- Maven
- JDK
- Intellij IDEA
安装Scala插件
打开 IDEA ,点击【IntelliJ IDEA】 -> 【Preferences】 -> 【Plugins】,搜索 “Scala”,搜索到插件然后点击底部的 【Install JetBrains plugin…】安装重启即可。
Gatling Maven工程
创建Gatling提供的gatling-highcharts-maven-archetype,
在 IntelliJ中选择 New Project
-> Maven
-> Create form archetype
-> Add Archetype
,在弹出框中输入一下内容:
GroupId: io.gatling.highcharts
ArtifactId: gatling-highcharts-maven-archetype
Version: 3.0.0-RC3
点击查看最新版本: 最新版本
之后输入你项目的GroupId(包名)和ArtifactId(项目名)来完成项目创建,
项目创建完成后,Maven会自动配置项目结构。
注:在创建的工程,修改pom.xml文件,添加如下配置,加快构建速度:
<repositories>
<repository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
工程项目目录
工程项目结构如下图:
项目目录说明:
- bodies:用来存放请求的body数据
- data:存放需要输入的数据
- scala:存放Simulation脚本
- Engine:右键运行跟运行
bin\gatling.bat
和bin\gatling.sh
效果一致 - Recorder:右键运行跟运行
bin\recorder.bat
和bin\recorder.sh
效果一致,录制的脚本存放在scala目录下 - target:存放运行后的报告
至此就可以使用IntelliJ愉快的开发啦。
Gatling测试SpringBoot
Gatling基于Scala开发的压测工具,我们可以通过录制自动生成脚本,也可以自己编写脚本,大家不用担心,首先脚本很简单常用的没几个,另外gatling封装的也很好我们不需要去专门学习Scala语法,当然如果会的话会更好。