Generating Sample Data for Integration Tests

Programming Sep 27, 2018

I was recently faced to introduce a development environment for one of my projects. This environment includes a simple demo data generator.

The database should be filled with data, covering almost every 'edge case' of the web app. The reason for this is, to be able to run integration tests on the application without affecting the real customer data and to make a local development of the source code possible.

Why not use the real customer data? I think, it is not a good idea to use this data, even if it is copied to a separate system. It is possible to accidentally send an E-Mail to a real customer address, for example during an integration test. (It is also possible to use services like mailtrap to prevent something like this)

I decided to build a script, which inserts data and simulate the real data. The concept I implemented, contains multiple JSON (JavaScript Object Notation) files and one SQL file.

The SQL file contains the complete database structure and will be executed first. The database will now have the current table structure without any data.

A JSON file looks something like this:

    table: "users",
    data: [
            id: 1,
            name: "example",

This makes it easy to loop through all JSON files and insert the data array in the provided table.

Please comment below, if you have any questions.




Howdy! I'm Stefan and I am the main author of this blog. If you want know more, you can check out the 'About me' page.

Impressum | Data Privacy Policy | Disclaimer
Copyright: The content is copyrighted and may not be reproduced on other websites without permission.