Gatling 使用Maven plugin创建项目

一、工具

  • IntelliJ IDEA

二、环境

Gatling是使用scala语言编写的,所以需要搭建scala的运行环境

IntelliJ IDEA安装插件 Scala

  • IDEA 快捷建Ctrl + Alt + S 打开设置界面
  • 搜索 plugins ,点击 plugins
  • 点击下方的Install JetBrains plugins
    Plugins界面
  • 搜索Scala ,点击Install即可。
    下载plugins

三、创建Maven项目

方案一,导入Maven原型项目

Gatling Maven 原型项目链接

步骤
  • File -> New -> Project -> Maven
  • 添加原型项目,勾选原型项目io.gatling.highcharts:gatling-highcharts-maven-archetype创建工程
  • 导入原型工程


    正常创建工程即可,等待几分钟导入原型。
  • 文件结构:


  • data 用于存放你的数据
  • request-bodies 用于存放你的 request body
  • simulations 放在 src/test/scala 目录下。
运行 Gatling:

右键点击 Engine -> Run ,即可运行。效果和运行 bin\gatling.bat 一致。报告会放在 target 文件夹下(这个文件夹首次运行时会自动生成,运行结果也会提示报告文件路径)

运行 Recorder:

右键点击 Recorder -> Run,即可运行。效果和运行 bin\recorder.bat 一致。录制的文件默认放在 src/test/scala 下。

方案二,普通Maven项目,配置pom文件

创建一个普通的maven项目,然后配置pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ocg-gatling</groupId>
    <artifactId>Gatling-maven-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <gatling.version>2.3.0</gatling.version>
        <gatling-plugin.version>2.2.4</gatling-plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.gatling.highcharts</groupId>
            <artifactId>gatling-charts-highcharts</artifactId>
            <version>${gatling.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.3.2</version>
            </plugin>
            <plugin>
                <groupId>io.gatling</groupId>
                <artifactId>gatling-maven-plugin</artifactId>
                <version>${gatling-plugin.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <configFolder>src/test/resources</configFolder>
                    <dataFolder>src/test/resources/data</dataFolder>
                    <resultsFolder>target/gatling/results</resultsFolder>
                    <bodiesFolder>src/test/resources/bodies</bodiesFolder>
                    <simulationsFolder>src/test/scala</simulationsFolder>
                </configuration>
                <executions>
                    <execution>
                        <id>execution</id>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <simulationClass>simple.Api_Test</simulationClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

文件目录如下:


运行

运行pom.xml中配置的测试类

mvn gatling:execute

运行指定的类

mvn gatling:test -Dgatling.simulationClass=simple.Api_Test

参考资料

jenkins:应用篇(Gatling plugin的使用)
Gatling文档:Maven plugin

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容