Documentation

gitHub

Generate mock data for testing

Hackolade Studio allows you to generate fake but realistic data for your data models.  Using fake data can be useful during system development, testing, and demos, mainly because it avoids using real identities, full names, real credit card numbers or Social Security numbers, etc.  while using "Lorem ipsum" strings and random numbers is not a realistic enough to be meaningful.  Alternatively, one could use cloned production data, except that it generally does not exist for new applications, plus you would still have to mask or substitute sensitive data to avoid disclosing any personally identifiable information.

 

According to ThoughtWorks TechRadar 27: "Synthetic data is also useful for exploring edge cases that lack real data or for identifying model bias."

 

Moreover, manually generating fake data takes time and slows down the testing process, particularly if large volumes are required.

 

The solution is to use Hackolade Studio to generate mock data, i.e. synthetic or fake but realistic data.  With Hackolade, you can generate first names and last names that look real but are not, and the same for company names, product names and descriptions, street addresses, phone numbers, credit card numbers, commit messages, IP addresses, UUIDs, image names, URLs, etc..

 

Data generated here may be fake, but it has the expected format and contains meaningful values.  City and streets names for example are randomly composed from elements that mimic real names.  And you can set the desired locale so the data elements are localized for better contextual meaning.

 

Generating mock test data is a 2-step process:

  • one-time setup for each model: you must associate each attribute with a function to get a contextually realistic sample
  • each time you need to generate test data, you define the parameters of the run

 

 

Assign a Faker function to data model attributes

Hackolade leverages an open-source library for this feature: FakerJS, a generator of fake data based on static string input.  Faker provides a wide range of data categories, e.g. name, address, animal, company, commerce, date, database, finance, git, image, internet, phone, vehicle, etc.  Each category contains many sub-categories and options.

 

Before you start, you should familiarize yourself with the possibilities by consulting this guide.  Note that the question mark ? in our properties pane opens up the Faker guide page in your default browser:

Faker function properties pane

 

All you need to do is to copy a function from the Faker guide pages and paste it in the property in Hackolade, for example:

Faker function

to be pasted 

Faker function pasted

 

You may also paste functions with arguments, such as faker.name.firstName("female") or compose more sophisticated results by assembling functions with placeholders, for example:

    `${faker.address.zipCode()} ${faker.address.city()}`

    '${faker.address.zipCode()} ${faker.address.city()}'

 

Note that we accept functions wrapped by either backticks or single quotes.

 

It is NOT possible to use any non-faker method or plain JavaScript.

 

You can check the result in the JSON Data pane of the JSON/YAML Preview tab for the entity.  If a function is not correctly composed or is missing, our JSON Data generation will fallback on the sample property, if defined, or to a random string 'Lorem'

 

The Faker function property is only enabled for selected data types, mainly string and numeric, and associated data types.

 

The following model illustrates the capabilities to generate JSON Data:

Faker function JSON Data preview

 

 

using the following functions (in this case exported to Excel for easy bulk edit):

 

NameTypeFaker function
namestringfaker.name.fullName()
titlestringfaker.name.title()
companystring'${faker.company.name()}, ${faker.company.suffixes()}'
jobtitlestringfaker.name.jobTitle()
jobDescriptorstringfaker.name.jobDescriptor()
senioritynumberfaker.random.numeric()
dayOffstringfaker.date.weekday()
phonestringfaker.phone.phoneNumber('+1 (###) ###-####')

 

 

Note: you may change the locale, if different than English, in Tools > Options > Forward-Engineering > JSON Data.

 

Generate test data in bulk

Generating one sample document on screen is good, but of limited use.  The real benefit comes when you can generate large, if not massive, amounts of test data, for general testing, as well as performance, and even load testing.  

 

Hackolade can generate 2 types of test data:

  • JSON documents for any model entity
  • records or documents to be inserted in database instances, where applicable

 

Create test JSON documents on file system

For any entity in a Hackolade data model, you can easily generate sample data with the menu Tools > Forward-Engineer > JSON Document.  You can select the entity or entities of your choice.  Then you specify the number of documents, and whether or not to minify the output:

 

Faker JSON Doc forward-engineering selection

 

After you choose the folder path, the application will create a JSON file containing an array of sample documents:

 

Faker JSON Doc forward-engineering output

 

Insert documents or records in database instance

Starting with v6.1.3 for MongoDB (and progressively thereafter for other targets), you may also generate synthetic data in bulk and apply it to a database instance.  All you need to do it to go to the scripot tab, select "Include sample data", and specify the number of documents per collection.  Then click the "Apply to instance" button and choose the target instance from the Connection settings dialog.

 

Faker bulk synthetic data applied to instance