Gradle與Gatling指令碼整合

來源:互聯網
上載者:User

標籤:des   http   java   使用   os   檔案   

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。

123456
repositories {    mavenCentral ()    maven {        url ‘http://repository.excilys.com/content/groups/public‘    }}

再加入scala和gatling的依賴項。

1234
dependencies {    compile ‘org.scala-lang:scala-library:2.10.1‘    testCompile ‘io.gatling.highcharts:gatling-charts-highcharts:2.0.0-M3a‘}

把conf檔案夾作為test的source檔案。

1234567
sourceSets {    test {        resources {            srcDir ‘conf‘        }    }}

建立一個名為gatling的task,目的是運行所有的gatling指令碼。

1234567891011121314151617181920212223242526
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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.