Gatling作为次时代的性能测试工具,由于其API简洁明了、性能出众,越来越受欢迎。但是运行Gatling脚本却有诸多不便,其提供的默认方式不是很方便。考虑到Gatling脚本本质上是Scala类,运行的时候还是使用的是java虚拟机,我们可以将其脚本的运行与Gradle结合起来。这样子就可以通过Gradle来运行Gatling脚本了。

废话少说,接下来就讲述下如何来进行配置。

创建一个标准的maven结构的工程目录,如下图所示。

conf目录存放Gatling的基本配置文件。
Gatling的脚本文件存放在src/test/scala/simulations包里面。可以自行在此包下对脚本文件再分类。

在build.gradle文件中引入scala插件。

1
apply plugin: 'scala'

然后引入有gatling库的maven repo。

1
2
3
4
5
6
repositories {
mavenCentral ()
maven {
url 'http://repository.excilys.com/content/groups/public'
}
}

再加入scala和gatling的依赖项。

1
2
3
4
dependencies {
compile 'org.scala-lang:scala-library:2.10.1'
testCompile 'io.gatling.highcharts:gatling-charts-highcharts:2.0.0-M3a'
}

把conf文件夹作为test的source文件。

1
2
3
4
5
6
7
sourceSets {
test {
resources {
srcDir 'conf'
}
}
}

创建一个名为gatling的task,目的是运行所有的gatling脚本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
task gatling (dependsOn: 'compileTestScala') << {

    logger.lifecycle (" ---- Executing all Gatling scenarios from: ${sourceSets.test.output.classesDir} ----")

    sourceSets.test.output.classesDir.eachFileRecurse { file ->
if (file.isFile ()) { def gatlingScenarioClass = (file.getPath () - (sourceSets.test.output.classesDir.getPath () + File.separator) - '.class')
.replace (File.separator, '.') javaexec {
main = 'io.gatling.app.Gatling'
classpath = sourceSets.test.output + sourceSets.test.runtimeClasspath
args '-sbf',
sourceSets.test.output.classesDir,
'-s',
gatlingScenarioClass,
'-rf',
'build/reports/gatling'
}
} } logger.lifecycle (" ---- Done executing all Gatling scenarios ----")
}

这是借助于Gatling的command line运行功能来实现的。具体参数指定官网上有,这里贴出原文。

Command Line Options #
Gatling can be started with several options listed below:

  • -nr (–no-reports): Runs simulation but does not generate reports
  • -ro (–reports-only ): Generates the reports for the simulation log file located in /results/
  • -df (–data-folder ): Uses as the folder where feeders are stored
  • -rf (–results-folder ): Uses as the folder where results are stored
  • -bf (–request-bodies-folder ): Uses as the folder where request bodies are stored
  • -sf (–simulations-folder ): Uses as the folder where simulations are stored
  • -sbf (–simulations-binaries-folder ): Uses as the folder where simulation binaries are stored
  • -s (–simulation ): Uses as the name of the simulation to be run
  • -sd (–simulation-description ): Uses as simulation description

我在github上创建了一个示例项目,请参见https://github.com/huangbowen521/gatling-gradle

Gradle与Gatling脚本集成的更多相关文章

  1. 【原】Gradle调用shell脚本和python脚本并传参

    最近由于项目自动化构建的需要,研究了下gradle调用脚本并传参的用法,在此作个总结. Pre build.gradle中定义了$jenkinsJobName $jenkinsBuild两个Jenki ...

  2. Gatling脚本编写技巧篇(二)

    脚本示例: import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.concurrent.durati ...

  3. Gatling脚本编写技巧篇(一)

    一.公共类抽取 熟悉Gatling的同学都知道Gatling脚本的同学都知道,Gatling的脚本包含三大部分: http head配置 Scenario 执行细节 setUp 组装 那么针对三部分我 ...

  4. 用Jenkins+Gradle+Jetty实现持续集成、测试、部署

    自动集成有很多种方案,本例用到的工具是Jenkins(前身Hudson)+Gradle+Jetty,关于Gradle可参考上一篇,Gradle常见问题. 本例项目名称: WAP Jetty 安装Jen ...

  5. 基于Jenkins+Git+Gradle的Android持续集成

    本文参考了: http://my.oschina.net/uboluo/blog/157483 http://java.dzone.com/articles/automating-continuous ...

  6. java~springboot~gradle里的docker集成

    在springboot里,我们的task任务可以添加docker构建的功能,在gradle集成环境里,直接可以实现编译,测试,打包镜像的流水线作业,很是方便! 下面分享给大家,在gradle里添加do ...

  7. Gradle:构建脚本概要

    一.构建块 1.每一个构建块都包括三个基本构建块:project.task和property: 2.每一个构建块包括至少一个project,进而又包括一个或多个task: 3.project和task ...

  8. gradle多模块构建集成swagger

    1.首先说一下软件的版本:springboot:1.5.2:springcloud:D-SR1:swaager2:2.6.0:gradle:4.5.工程模块是分开的单独的entity,api,mapp ...

  9. postman(九):postman接口测试脚本集成到jenkins

    本篇的目的是实现使用jenkins远程执行postman接口测试脚本 准备工作:一台linux服务器(可以用虚拟机搭建一个),linux服务器上安装好node.js.newman,部署好jenkins ...

随机推荐

  1. 第一节(配置springmvc环境)学习尚硅谷-springmvc视频教程

    之前,一直从事C#开发.后来,公司调整后领导决定使用java开发,因此需要收集相关学习资料.该视频教程比较入门,也适合自己,于是边看边写的同时再总结一下便于自己牢记,遇到分歧不对之处望指正. 开发环境 ...

  2. 【Git】简单地使用github当做远程共享仓库

    简单地使用github当做远程共享仓库 1.进入各自的github,选取一个人的github作为总的远程共享仓库,其余成员每次修改完项目后pull request请求合并自己的修改内容. 2.其余开发 ...

  3. 4580: [Usaco2016 Open]248

    Description Bessie likes downloading games to play on her cell phone, even though she does find the ...

  4. 查询时,如何保存获取相关路径url

    作为新人,总是会有许多小问题不懂,不知道如何解决的. 这不,这次,遇到了路径获取问题. 在Jsp页面中,获取当前路径,在<script></script>中添加  var ur ...

  5. js创建对象的几种方式

    /** * 顺便重温一下对象的创建方式 * 代码简单说明问题就好 * 概念性的东西这里就不提了,只加上自己简单理解 */ /** * 工厂模式,就是将手动的创建细节封装在一个方法里, * return ...

  6. Spring整合MyBatis

    前言:MyBatis 是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis 消除了几乎所有的JDBC代码和参数的手工设置以及结果集的检索.MyBatis 使用简单的XML或注解用 ...

  7. IE 浏览器 如何关闭令人讨厌的“此网站需要运行以下加载项:XXX。如果您信任该网站和该加载项并允许运行该加载项,请单击这里...

    1.运行gpedit.msc 2.在打开的组策略中打开用户配置——管理模板——Windows组件——Internet Explorer 3.选择“关闭ActiveX选择启用提示”,将其状态改为“已启用 ...

  8. 『TCP/IP详解——卷一:协议』读书笔记——14

    2013-08-25 11:32:06 第5章 RARP:逆地址解析协议 5.1 引言 具有本地磁盘的系统引导时,一般是从磁盘上的配置文件中读取IP地址.但是无盘机,如X终端或无盘工作站,则需要采用其 ...

  9. Codeforces #380 div2 B(729B) Spotlights

    B. Spotlights time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  10. 关于Certificate、Provisioning Profile、App ID的介绍及其之间的关系

    1.概念介绍 如果你拥有一个开发者账户的话,在iOS Dev Center打开Certificates, Indentifiers & Profiles,你就可以看到如下的列表: Profil ...