2017-04-05 53 views
4

我正在尝试使用Gatling加载测试Web服务。这是我的build.sbt我如何通过SBT实际运行Gatling测试

import io.gatling.sbt.GatlingPlugin 

val gatlingVersion = "2.2.4" 

val dependencies = Seq(
    "io.gatling" % "gatling-core" % gatlingVersion, 
    "io.gatling" % "gatling-http" % gatlingVersion 
) 

lazy val project = 
    Project("gattling-tests", file(".")) 
     .enablePlugins(GatlingPlugin) 
     .settings(
     javaOptions in Gatling := overrideDefaultJavaOptions("-Xmx4G"), 
     scalaVersion := "2.12.1", 
     libraryDependencies ++= dependencies 
    ) 

在测试文件夹我创建延伸模拟类,它有我的方案和HTTP请求。

import io.gatling.core.Predef._ 
import io.gatling.http.Predef._ 

class ShieldAuthLoadTests extends Simulation { 
    val httpConf = http 
     .baseURL("http://localhost:8080/api/1/") 
     .acceptHeader("application/json") 
     .contentTypeHeader("json") 

    val login = http("Login") 
     .post("login") 
     .formParam("username", "foo") 
     .formParam("password", "bar") 
     .check(status.is(200), jsonPath("$..response.id").ofType[String].saveAs("id")) 

    val get = http("get") 
     .get("/api/api1") 
     .header("token1", "$id") 
     .check(status.is(200), jsonPath("$..response").exists) 

    val scn = scenario("scn") 
     .exec(login) 
     .pause(3) 
     .exec(get) 

    setUp(scn.inject(atOnceUsers(10)).protocols(httpConf)) 
} 

我的希望是,当我会做sbt gatling:test它会运行gatling测试。但是当我运行sbt gatling:test它只是在没有运行测试的情况下取得成功。

quickstart说明文件$GATLING_HOME/bin/gatling.sh但我没有gatling.sh,因为我想通过SBT进行测试。

回答

5

该文档有点不一致,因为我遇到类似的问题。

我总是基于我的项目this只是为了确保。

无论如何,它看起来像你的依赖关系的问题。尝试将它们改为此以代替...

val dependencies = Seq(
    "io.gatling.highcharts" % "gatling-charts-highcharts" % "2.2.4" % "test,it", 
    "io.gatling"   % "gatling-test-framework" % "2.2.4" % "test,it" 
) 

或参见here