Wednesday, August 30, 2017

Data Generation of test data

Writing your own test data generator

There are cases where it makes sense to generate data in your SQL Server database. If you are dealing with one table this can be a pretty straight forward task and you may consider writing it yourself as a simple app or code that runs before your tests run.

The hard part to rolling your own generator for a single table is the generation of data. There are some nuget packages that will help with this.

NBuilder - this is great for creating object graphs. It should be able to play with Entity Framework and be saved to database. In theory in situ updates could be done.

Bogus - you can save changes using Entity Framework to the database. The relationships would be handled by entity framework automatically. If the data is loaded from the data and then updated using Bogus generated data the data could be anonymized in situ. It does have really nice options for rules the data must follow.

REX - a command line tool to generate data that follows a regular expression. Very cool.

Free-ish products for generating data for single table

If you don't want to roll your own there are other options as well for simple one table type options. Below are some you may want to check out:

Yan DATA - It is a web based tool that requires you to enter your table definition into a web form and then generate the data from there. This one is nice in that it support many formats as output like SQL, JSON, Excel, XML, CSV, and HTML. It does up to 10,000 rows and is free / donation.

Mockaroo - It is similar to Yan DATA, but is limited to 1000 rows or $50 or $500 / year and its focus is on realistic data types. It even has datatypes for specific industries. It has some additional options for outputting the data including some that are database specific, etc. Interestingly they do have a REST url you can use to get data and use in your automation. It does also allow you to define your tables based on table create SQL statements or Excel column headers. It also lets you specify a formula for a column and specify how many empty values should be used.

Products for generating data for multiple related tables (they have a price)

DevArt dbForge Data Generator - appears to be a very similar tool.