簡體   English   中英

如何在 Gatling 中為相同的變量名提供隨機數

[英]How to feed random numbers for the same variable names in Gatling

如果你有一個 JSON,它有一個客戶數組,每個客戶都必須有一個唯一的客戶編號,我如何用隨機數來提供它:

    {
        "customers": [
            {
                "customerNo": "123",
                "Name": "Joe"
            },
            {
                "customerNo": "456"
                "Name": "Jane"
            },
        ]
    }

我認為這可能有效:

    {
        "customers": [
            {
                "customerNo": "${customerNo}",
                "Name": "Joe"
            },
            {
                "customerNo": "${customerNo}"
                "Name": "Jane"
            },
        ]
    }
    val customerNumber = Iterator.continually(
      Map("customerNumber" -> Random.nextInt(Integer.MAX_VALUE))
    )

然后通過添加:

    feed(customerNumber)

但這在兩種情況下都使用相同的生成數字。

最干凈的方法是傳遞 function,例如 Java:

StringBody(session ->
"""
{
  "customers": [
    {
      "customerNo": "%s",
      "Name": "Joe"
    },
    {
      "customerNo": "%s"
      "Name": "Jane"
    },
  ]
}""".formatted(Random.nextInt(Integer.MAX_VALUE), Random.nextInt(Integer.MAX_VALUE))
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM