When using the apipost interface for interface testing, some parameters need to generate random and non-repetitive values when passing parameters in json format through the post interface.

Apipost Built-in mock field variables

We just need to directly copy the variables we need in JSON to use

We can also customize mock variables. We write custom mock variables in the pre-execution script of the interface. We define a mobile phone number and set it to an environment variable or global variable

const phonePrefix = [‘132’, ‘135’, ‘189’]

const index = Math.floor(Math.random() * phonePrefix.length)

var phone = phonePrefix[index] + Mock.mock(/\d{8}/)

apt.variables.set(“phone”, phone);

You can then call the environment variable or global variable in JSON