At a recent client engagement, my colleague had to create some location data for testing one of the client application. The data creation involved multiple steps like downloading some data from the net, removing some columns, transforming it as per needs using Python code. The process was a bit time-consuming. Recently when I was searching for some tools for data gathering I chanced upon a tool called Mockaroo. Mockaroo is an excellent tool for generating realistic test data. I found it really helpful and it fit my needs very well. This post is about how I could use different features of Mockaroo which I felt would be very helpful for anyone testing data intensive applications.
Data Requirements
Our requirement was a bit more complex than just using random names or address. We had fields like Longitude, Latitude, Address, Area calculation mode, Radius, Travel mode, Travel type. Longitude and Latitude attributes are based on the location details. The Address field is a combination of Street, Province, and Postal Code. Area calculation mode has two dependent parameters ‘radius’ and ‘travel-time’. If area calculation mode is ‘radius’ then we had to set the ‘radius’ parameter to be a radius in miles. If the area calculation mode was set to ‘travel-time’, we had to set ‘travel mode’ to one of “Bike”, “Walk”, or “Drive” and then we had to set the value of ‘travel-time’ to a number of minutes around the location. The fields ‘travel mode’ and ‘radius’ correspond with the field ‘area calculation mode’. As you can guess, a lot of manual effort was needed for populating this kind of test data.
Using Mockaroo to generate the data
Mockaroo is a brilliant online tool that lets you solve the data generation problems in a few clicks. It provides a GUI to build some data that suits your needs and lets you generate up to 1,000 rows of realistic test data in CSV, JSON, SQL, and Excel formats. It generates data from a saved schema which can be helpful for automated testing.
The tool has columns for data field names, their data types and blank options which you can alter to adjust the data order and specifications. You simply enter a field name and select a data type. You can move fields up using the handle bars on the left, or delete fields using the cross on the right. The column named ‘Field Name’ accepts simple text input, ‘Type’ accepts data type and ‘Options’ accepts numerical input. You can add more fields by clicking on the “Add another field” button.
Mockaroo supports around 74 different types, each of these data type provides a range of appropriate sample data that is used to populate the field. You can view the list of 74 types on the API docs page as shown below. You can also customize the data types according to your data needs.
Different operations using Mockaroo Data Types
Mockaroo has a lot of useful features. In this section, I’ll talk about the ones I found most useful features like Formulas, Functions, Custom List which we have applied for data transformations specific for our requirement. Here is link to location_details Schema which we created for our data creation (See Mockaroo- Location_details Schema image)
Longitude and Latitude Data types
Generating realistic data for Longitude and Latitude fields in our data set was a time-consuming process. Mockaroo made it simple. Mockaroo supports a data type called Longitude and Latitude which allows us to generate data for longitude and latitude values for the given location details. This helped us to create this data quickly and made our job simple.
Custom List
Custom List is another data type which is appropriate for populating default values in the fields. It picks items randomly or sequentially from a custom list of values specified. For our requirement, we choose Custom List values for the field ‘Area calculation mode’ to generate random data values ‘radius’ or ‘travel-mode’ for each row.
Formula
Formula is a powerful feature of Mockaroo to generate any kind of data we want. You can use formulas to create your own data types in Mockaroo. It helps to reference existing fields and generate data based on the custom code. Using formulas you can do things like writing different functions for date diff, concatenate strings, mathematical calculations, conditional logic etc…, Any kind of data transformation is made simple using these formulas.
Concat Function
The Address field in our requirement is a combination of Street, Province, and Postal code. We used concat function to concatenate all these strings. The Mockaroo API doc has all the syntax for different functions. Please see the above image for the concat function. Similarly, you can use different logical operators, functions, Regular Expressions to do data transformations.
Conditional IF Statements
If you want a value based of some incoming value from another field you can utilize conditional IF statements. In our case, for the field radius, we want to generate some values from 1 to 20 based on another field called Area calculation mode. So we could achieve this by using IF conditional statements(See below image for formula).
If you notice in the location_details schema, you’ll also see that there are a couple of extra variables which we don’t need in our dataset. These variables are commonly found when you create data using formulas. Mockaroo allows us to hide the fields which we don’t need in our desired data set. You can just type ‘__'(two underscore) characters in front of the field you want to hide, it will be automatically hidden. This is useful when creating intermediate fields for use in formulas and templates. For example, in our case the fields like ‘___address_type’,’__state_type’,’__province’, ‘__postal_code’ were created to refer in the concat function to generate data for Address field.
Apart from these feature Mockaroo provides with some additional features which are useful like
- Specify number of rows to be generated.
- The ‘Download Data’ button to download the data.
- You can preview what data will be downloaded by clicking on the “Preview” button.
- You can save the setting to your profile through the “Clone This Schema” button
- Import fields from csv or sql
Once you are done with the field manipulations, you can save this schema and once you save this schema you’ll be given a Share Link to the schema.
Mockaroo Rest API
Mockaroo provides a REST API, which lets you download randomly generated data into your projects in real-time with unlimited calls. Using REST API you can easily integrate into test automation workflow for repeatable test data generation. You can download based on a saved schema or fields you define at runtime. Anything you can generate via the website can also be generated via the REST API.
The API contains a single method:
POST https://api.mockaroo.com/api/generate(.format) |
This method will return CSV or JSON formats depending on the file type part of the URL. You can find more details on Mockaroo REST API here
I found Mockaroo is a really great, free product and is perfect if you need to generate test data quickly.
If you are a startup finding it hard to hire technical QA engineers, learn more about Qxf2 Services.
References
1. Creating Test Data with Mockaroo
2. How to generate random, realistic & reliable data for your application?
3. Generate Test Data Quickly In Two Easy Steps
I am an experienced engineer who has worked with top IT firms in India, gaining valuable expertise in software development and testing. My journey in QA began at Dell, where I focused on the manufacturing domain. This experience provided me with a strong foundation in quality assurance practices and processes.
I joined Qxf2 in 2016, where I continued to refine my skills, enhancing my proficiency in Python. I also expanded my skill set to include JavaScript, gaining hands-on experience and even build frameworks from scratch using TestCafe. Throughout my journey at Qxf2, I have had the opportunity to work on diverse technologies and platforms which includes working on powerful data validation framework like Great Expectations, AI tools like Whisper AI, and developed expertise in various web scraping techniques. I recently started exploring Rust. I enjoy working with variety of tools and sharing my experiences through blogging.
My interests are vegetable gardening using organic methods, listening to music and reading books.
Thank you for your post,it is really very helpful.
Can you please answer my below query ?
How to generate Germany address or any country specific address in Mockaroo, as I am able to generate only US address.
Field name : address
type: street address
Field name : zippostcode
type: Postal code
Field name : city
type: city
Field name : country
type: country code for (Germany : DE)
Field name : state
type: state
In above scenario, I am getting Germany related valid values for zippostcode,city, country,state except address in which I am getting US values for street address.
Test data generated :
[{
“address”: “4 Springs Lane”, >>>>>>>>>>>>>> This is US address and I would like to generate Germany address
“zippostcode”: “35687”,
“city”: “Dillenburg”,
“country”: “DE”,
}]
Hi Sayali,
I too see that for country Germany – the address is filled with US. I happen to check what is the mail address format in Germany using this link – https://german.stackexchange.com/questions/28167/what-is-the-address-format-i-should-use-for-sending-a-letter-mail/28174
Based on the above link instead of the address field if we use following fields – street number, street name, city, country, postal code,I am getting the correct address present in Germany, you may try the same.
Let me know if this is useful.
Thanks & Regards,
Rohini
Hello Rohini,
Thank you so much for replying me back and sorry for late reply.
As per your suggestion,I have used street number, street name, city, country, postal code but not getting the correct address present in Germany.
Field Name : Type
address1 : street number
address2 : street name
city : city
country : country code –Germany
zippostcode :postal code
Test data generated :
[{
“address1”: “463 “,
“address2”: “Fulton”,
“city”: “Hannover”,
“country”: “DE”,
“zippostcode”: “30167”
}]
here, “463 Fulton” is US address.
Thanks and regards,
Sayali
Hello Rohini,
Thank you so much for replying me back and sorry for late reply.
As per your suggestion,I have used street number, street name, city, country, postal code but not getting the correct address present in Germany.
Field Name : Type
address1 : street number
address2 : street name
city : city
country : country code –Germany
zippostcode :postal code
Test data generated :
[{
“address1”: “463 “,
“address2”: “Fulton”,
“city”: “Hannover”,
“country”: “DE”,
“zippostcode”: “30167”
}]
here, “463 Fulton” is US address.
Thanks and regards,
Sayali
Hi Sayali,
I have tried with different types – street numbers, street name and all other options like placing Postal code before the name of the city etc., but the address returned is for US region. Looks like it is a bug in Mockaroo tool in generating correct address for Germany. I suggest you to kindly follow up on the Mockaroo Forum about this.
Thanks
Indira Nellutla
Hello Indira,
Thanks for your reply. I have already raised my issue in ‘Mockaroo Community Forum’ but did not get any answer.
“http://forum.mockaroo.com/t/how-to-generate-germany-country-specific-street-address/4553”
Thanks and Regards,
Sayali
Sayali,
If address is the only stopper, then you can get the address details for the zip code using GeoPy python package as shown below. It will help to find the details of a given zip code. So all you have to do is, after you download your data, just replace the address fields with the address you get from this code for that zip code.
Ref :- https://www.w3resource.com/python-exercises/geopy/python-geopy-nominatim_api-exercise-3.php
Hope this helps !
This Mockaroo tutorial is a valuable guide for generating authentic test data. It covers the essentials effectively, helping developers create lifelike data for testing. Great resource!