【问题标题】:Pass runtime arguments in Gatling在 Gatling 中传递运行时参数
【发布时间】:2021-03-30 23:03:42
【问题描述】:

我试图在运行几个字段的加特林测试时传递运行时参数。例如,我试图在运行测试时动态传递用户数量。我该怎么做?

【问题讨论】:

    标签: performance-testing gatling


    【解决方案1】:

    这记录在official documentation:

    这可以通过启动脚本中的附加 JAVA_OPTS 轻松完成:

    JAVA_OPTS="-Dusers=500 -Dramp=3600"
    
    val nbUsers = Integer.getInteger("users", 1)
    val myRamp = java.lang.Long.getLong("ramp", 0L)
    setUp(scn.inject(rampUsers(nbUsers).during(myRamp.seconds)))
    
    // Of course, passing a String is just as easy as:
    
    JAVA_OPTS="-Dfoo=bar"
    
    val foo = System.getProperty("foo")
    

    【讨论】:

      【解决方案2】:

      最简单的方法是使用 Java 系统属性,例如,如果您将 workload model 定义为:

      setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))
      

      如果您将其从硬编码更改为动态读取system property,例如:

      setUp(scn.inject(atOnceUsers(Integer.parseInt(System.getProperty("userCount")))).protocols(httpProtocol))
      

      您将能够通过-D command-line argument 动态传递所需数量的用户,例如:

      gatling.bat -DuserCount=5 -s computerdatabase.BasicSimulation
      

      更多信息:Gatling Installation, Verification and Configuration - the Ultimate Guide

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-09
        • 1970-01-01
        • 1970-01-01
        • 2023-02-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多