在加特林sbt项目中传递命令行参数

时间:2018-10-30 16:30:02

标签: scala sbt gatling

我想在加特林sbt项目中使用命令行参数传递加速用户,调节持续时间,保持持续时间等。

例如:

val rampUpUserCount  =  Integer.parseInt(System.getProperty("rampUpUsers"))
val rampUpDuration = Integer.getInteger(System.getProperty("rampUpDuration"))

我正在测试中

setUp(
    test.homePageScenario.inject(
      nothingFor(10 seconds),
      rampUsers(rampUpUserCount) over (rampUpDurationInMins minutes)
))

,并在我通过时通过命令行

 sbt gatling:testOnly simulations.test.gateway -DrampUpUsers=200 -DrampUpDuration=20

我得到NumberFormatException

16:28:44.570 [INFO ] a.e.s.Slf4jLogger - Slf4jLogger started
[error] java.lang.NumberFormatException: null
[error]     at java.lang.Integer.parseInt(Integer.java:542)
[error]     at java.lang.Integer.parseInt(Integer.java:615)
[error]     at simulations.SimulationConfig.$init$(SimulationConfig.scala:185)
[error]     at simulations.engineGateway.GetRecsFromThinkGateway.<init>(GetRecsFromThinkGateway.scala:10)
[error]     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[error]     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[error]     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[error]     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
[error]     at java.lang.Class.newInstance(Class.java:442)
[error]     at io.gatling.app.Runner.run0(Runner.scala:79)
[error]     at io.gatling.app.Runner.run(Runner.scala:64)
[error]     at io.gatling.app.Gatling$.start(Gatling.scala:59)
[error]     at io.gatling.app.Gatling$.fromArgs(Gatling.scala:43)
[error]     at io.gatling.sbt.GatlingTask.liftedTree1$1(GatlingTask.scala:51)
[error]     at io.gatling.sbt.GatlingTask.execute(GatlingTask.scala:50)
[error]     at sbt.ForkMain$Run$2.call(ForkMain.java:296)
[error]     at sbt.ForkMain$Run$2.call(ForkMain.java:286)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]     at java.lang.Thread.run(Thread.java:748)

请有人可以帮助我吗? 谢谢

1 个答案:

答案 0 :(得分:1)

您需要将参数移至任务gatling:testOnly

之前
 sbt -DrampUpUsers=200 -DrampUpDuration=20 gatling:testOnly simulations.test.gateway