首页 文章

如何从代码中运行gatling

提问于
浏览
8

I would like to run Gatling test from code. How to do it? 教程只说命令行和sbt .

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

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

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

2 回答

  • 7
    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)
    }
    

    希望这会有所帮助 .

  • 1

    我同意Gatling网站上的文档没有解释得那么好(我前几天查找过)但是Gatling提供了一个很好的示例,其中包含一些如何实现此目的的文档:

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

相关问题