【问题标题】:How to run gatling from code如何从代码运行加特林
【发布时间】:2015-09-13 02:15:40
【问题描述】:

我想通过代码运行 Gatling 测试。怎么做? 教程只说命令行和 sbt。

上下文:我想扩展测试。在后台我有我需要模拟的自定义套接字通信。从该模拟中,我需要将一些生成的 Id 传递给 Gatling 测试。我可以通过使用参数从我的模拟应用程序运行它来做到这一点(但我还不知道如何)。其他解决方案也是一个很好的答案。

我可以通过文件和 http://gatling.io/docs/2.1.6/cookbook/passing_parameters.html 做一些传递,但它很难看..

也许有办法从 scala 代码运行 sbt 任务?

【问题讨论】:

    标签: scala sbt performance-testing gatling


    【解决方案1】:
    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)
    }
    

    希望这会有所帮助。

    【讨论】:

    • 重要的是要注意数据和正文必须是真实的目录,而不是 jar 中目录的 URL。这使得从 jar 以编程方式运行 Gatling 相当棘手(需要复制到临时目录)。
    【解决方案2】:

    我同意 Gatling 网站上的文档解释得不是很好(我前几天找了它)但是 Gatling 提供了一个很好的示例,其中包含一些关于如何实现这一点的文档:

    https://github.com/gatling/gatling-sbt-plugin-demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-14
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      相关资源
      最近更新 更多