mockaroo
有件很困扰的事情,就是当某个功能开发完毕,想要测试的时候,往往咱开发人员需要自己绞尽脑汁想想测试数据,这个是很头痛的。。比如邮箱啊,手机号码啊之类的。有没有什么可以快速生成我们想要的测试数据?那就是mockaroo,mockaroo可以满足我们程序员的测试数据需求,而且使用方法很简单。让我们一起脱离那些很随意乱输的asdnadadasdassdasdadasda
数据吧。
网址: 初始化数据功能页
步骤
- 点开链接,我们来到生成数据页面:
FieldName是字段名称,类型是你想要选择随机生成怎么样的数据,比如我想生成邮箱。除了基本的类型外,还提供其他类型比如 : 位置地址,涉及到金融类型的(比如信用卡)、IBAN等,只需要点击这个下面的文件夹图标进行选择:
点击后,出现如下选择生成数据类型的列表:
假设我们有些行希望它不需要输入数据,是空白的。还可以对选择数据进行blank处理,这里指的是空白率。百分比越高,空白数据程度越大。
旁边的是Fx啥呢?实际上可以说是公式,假设我们需要对数据进行全部英文名称进行大小写,或者对整数进行增减。都可以进行操作。
接下来是底部,可以选择生成的行数,格式(CSV
、JSON
、SQL
、XML
等),。LineEnding是数据编码格式,这里是有Windows
和Unix
两种不同操作系统的系统选择。
有关Fx更多公式如下:
#Formulas
#Formulas allow you to use Ruby code to generate data based on custom logic. For example:
times_reached_base / at_bats + slugging
Operators
+ - * / %
Logic
< > <= >= == != and or
Conditional Statements
if my_num % 2 == 0 then 'even' else 'odd' end
if score > 10 then "high" elsif score > 5 then "medium" else "low" end
Functions
base64(str) => encodes a string as base64
code("CURRENT_TIMESTAMP") => returns a value that is will not be wrapped in quotes in the downloaded file. Use this to inject code into your data.
concat(first_name, " ", last_name) => concatenates all arguments into a single string.
date('7/4/2015') => July 4, 2015. You can optionally pass a format string as a second argument. The default format is "%m/%d/%Y". See Ruby Date.strptime for more info on formats.
date_diff('days', my_date, date('2015-01-01')) => The numbers of days between my_date and Jan 1, 2015. 'days', 'hours', 'minutes', and 'seconds' are also supported.
day(my_date_field) => The day of my_date_field as an integer. Optionally specify true as a second argument to return the day as string in 2 digit format.
digest(str, 'MD5|HMAC|RMD160|SHA1|SHA256|SHA384|SHA512', 'hex|base64') => digest of str with specific algorithm and encoding
epoch(datetime) => Converts a datetime field to an epoch.
field("My Field Name") => gets the value of a field. Use this to access fields that start with an uppercase letter or contain non-alphanumeric characters.
from_dataset("dataset", "column", join_criteria) => Fetches a value from a dataset.
For example, from_dataset("People", "name", id: person_id) returns the value of the "name" column from the "People" dataset where the id column matches the person_id column in the current schema.
hex(str) => encodes a string as hex
lower("XYZ") => xyz
mongo_object_id(my_id) => Output the value of my_id in MongoDB ObjectId JSON format
month(my_date_field) => The month of my_date_field as an integer. Optionally specify true as a second argument to return the month as a string in 2 digit format.
my_date + years(2) => the date 2 years after my_date. months, days, hours, minutes, and seconds are also available.
naughty(my_field, 10) => returns a naughty string 10% of the time and the value of my_field 90% of the time. Use with hidden fields (name starting with "__") to turn nice fields into naughty fields!
now() => The current date and time.
pad(field, length, fill_string, "left|right|center") => pads a string to a fixed length with filler.
format(number_value, decimals) => formats a number as a string with a fixed number of decimal places. For example: format(1.2, 3) => "1.200"
random(min, max) => generates a random number between min and max.
round(x / y, 2) => rounds to 2 decimal places
time(my_datetime_field => Returns only the time part of a datetime field.
upper("xyz") => XYZ
year(my_date_field) => The year of my_date_field as an integer
Accessing Request Parameters when Used in a Mock API
request_params['name_of_parameter'] => returns the value of a URL or query string parameter specified in the request
request_entity['name_of_parameter'] => returns the value of a key in the JSON request entity body
Handling Blanks
my_num + 1 if my_num => returns my_num + 1, or blank if my_num is blank
a + b if a and b => returns a + b, or blank if either is blank
(my_num || 0) + 1 => returns my_num + 1, or 1 if my_num is blank
if my_field.nil? then 'blank' else 'not blank' end => "blank" when my_field is blank, otherwise "not blank"
Accessing Nested JSON Objects
When a formula field is inside of a JSON array it has access to all fields in that array as well as all fields on parent objects. Both fields in the array and parent fields are accessed without a qualifier. For example, if a formula is in an array named "myArray" that has nested field named "myArray.myField", the formula can access that field as "myField" NOT "myArray.myField". When formulas need to access fields in nested objects (not in an array), however, the fully qualified field name must be used.
- 接下来点击提交,我这里保存为Json格式
- 打开文件,查看