Response Templating - Random Values
Generating random values
WireMock Cloud provides two random value helpers - randomValue
and pickRandom
.
Random strings
The randomValue
helper generates random strings of a specific type and length.
Optionally, values containing alphabetic characters can be made upper case via the uppercase
parameter.
Random numbers
While the randomValue
helper can generate a number as a string when type NUMERIC
is requested,
sometimes it can be useful to emit an actual typed number with the ability to control
lower and upper bounds. Working with numbers this way supports further processing
with the math
helper or can serve as input to the range
helper, among other uses.
The randomInt
helper emits random integers with one, both or neither bound specified.
Likewise randomDecimal
will emit random decimals:
Pick random
The pickRandom
helper randomly selects a value from its parameters.
If the first parameter is a collection then the value will be randomly selected from within this:
Otherwise a value will be picked from the list of parameters provided:
If you desire multiple unique elements to be randomly pulled from the list, a count
option can be supplied to the
helper.
In this case, the result will be a list, instead of a single value.
For example, the following template:
will produce a list similar to the following: