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. MMS源码中异步处理简析

    1,信息数据的查询,删除使用AsycnQueryHandler处理 AsycnQueryHandler继承了Handler public abstract class AsyncQueryHandle ...

  2. 深入研究C语言 第一篇

    一. 研究过程 1.第一章:创建编译环境: 我们首先下载TC2.0,找到其中与编译连接相关的程序和文件: (1) 编译器:TCC.exe (2) 连接器:tllike.exe (3) 相关文件:c0s ...

  3. 收藏的 500多个开源的Git源码

    由dkhamsing发起的Open-Source iOS Apps收集了各种开源的iOS App,并进行了详细的分类,比如游戏.社交.健康.键盘.定位.多媒体.新闻.办公.安全以及小工具类等.截至目前 ...

  4. Mono for android 如何动态添加View,线程内部如何更新UI.

    貌似所有设计到UI的程序原理都是一样的,子线程是不能够更新UI状态的,所以就必须使用UI自身或者第三方来更新UI. 如 在WinForm 中 就可以使用Control.Invoke(Action ac ...

  5. 安装Openfile环境和组件XMPP

    打开ProFTPD和Apache Web Server 安装Openfile 在系统偏好设置中打开Openfile,开启Openfile状态 在safair浏览器中输入127.0.0.1:9090 配 ...

  6. SortedDictionary

    对一个Dictionary<TKey, TValue>进行键排序可以直接用SortedDictionary SortedDictionary<TKey, TValue> 泛型类 ...

  7. selenium-pageobject设计模式

    from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom time import sleepfrom ...

  8. Mvc模板页

    以前学过WEB的应该都知道母版页这个东西,在这里呢,mvc的模板页和WEB中的模板页也是一样的效果和用途. 首先:创建一个项目,控制器,生成Index视图,在生成视图的时候我们选择Razor视图引擎, ...

  9. tmpfs介绍

    tmpfs 前几天发现服务器的内存(ram)和swap使用率非常低,于是就想这么多的资源不用岂不浪费了?google了一下,认识了tmpfs,总的来说tmpfs是一种虚拟内存文件系统正如这个定义它最大 ...

  10. 那年有关 return ; 的一切

    现在只知道在dev C++里面声明了函数的返回类型不为void就不能写return; ,但是如果返回值为void就可以写return; ,而且如你所愿.