[英]How to feed random numbers for the same variable names in Gatling
If you have a JSON, where it has an array of customers where each customer has to have a unique customer number, how can I feed this with random numbers:如果你有一个 JSON,它有一个客户数组,每个客户都必须有一个唯一的客户编号,我如何用随机数来提供它:
{
"customers": [
{
"customerNo": "123",
"Name": "Joe"
},
{
"customerNo": "456"
"Name": "Jane"
},
]
}
I thought this might work:我认为这可能有效:
{
"customers": [
{
"customerNo": "${customerNo}",
"Name": "Joe"
},
{
"customerNo": "${customerNo}"
"Name": "Jane"
},
]
}
val customerNumber = Iterator.continually(
Map("customerNumber" -> Random.nextInt(Integer.MAX_VALUE))
)
Then by adding:然后通过添加:
feed(customerNumber)
But this uses the same generated number in both cases.但这在两种情况下都使用相同的生成数字。
The cleanest way is to pass a function, eg in Java:最干净的方法是传递 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.