如何从代码运行加特林 [英] How to run gatling from code
问题描述
我想从代码运行 Gatling 测试.怎么做?教程只说命令行和 sbt.
I would like to run Gatling test from code. How to do it? Tutorials says only about command line and sbt.
上下文:我想扩展测试.在后台,我有需要模拟的自定义套接字通信.从那个模拟中,我需要将一些生成的 Id 传递给 Gatling 测试.我可以通过使用参数从我的模拟应用程序运行它来做到这一点(但我还不知道如何).其他解决方案也是一个不错的答案.
Context: I would like to extend tests. In background I have custom socket communication which I need to simulate. From that simulation I need to pass some generated Ids to Gatling test. I could do it by running it from my simulation app with parameters (but I don't know yet how). Other solution would be also a good answer.
我可以通过文件和http://gatling.io/docs/2.1.6/cookbook/passing_parameters.html ,但它很难看..
I could do some passing through file and http://gatling.io/docs/2.1.6/cookbook/passing_parameters.html , but it is ugly..
也许有办法从 Scala 代码运行 sbt 任务?
Maybe there is way to run sbt task from scala code?
推荐答案
import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder
object Engine extends App {
val props = new GatlingPropertiesBuilder
props.simulationClass("your.simulation.class.goes.here")
props.dataDirectory("path.to.data.directory") //optional
props.resultsDirectory("path.to.results.directory") //optional
props.bodiesDirectory("path.to.template.directory") //optional
props.binariesDirectory("path.to.binaries.directory") //optional
Gatling.fromMap(props.build)
}
希望这会有所帮助.
这篇关于如何从代码运行加特林的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!