Test Data Challenge

A Tester wants to use GenRocket to populate two database tables with synthetic test data, a User table and an Address table respectively.  The User table is the parent of the Address table, which means an Address may not exist unless it belongs to a given User. The Tester also wants the User and Address tables to create their own primary keys and not have GenRocket create them.


But, this creates a challenge for the Tester. When GenRocket runs a Scenario that generates test data to populate a given database table, it generates its own unique Id for each row and that unique Id is normally stored as the primary Id for that row; however, in this instance, since the User table is generating its own primary Id, the User Scenario will not store GenRocket's unique Id as the primary Id.  


Since the Address table is a child of the User table, its GenRocket Scenario must assign a unique user Id to each Address to guarantee referential integrity between a User and an Address. However, within the Address Scenario, the generation of unique User Ids will follow the identical pattern as was generated in the User Scenario, as it should; but, remember, the unique user Id generated by GenRocket is not the primary Id that was stored in the user table. This is where the Test Data Mapping Design Pattern comes in to play using a concrete mapping table to map a GenRocket synthetically generated Id to a Database generated primary Id.


Test Data Generation Diagram

The Test Data Generation diagram, shown below, describes how the Mapping Design pattern is utilized to map GenRocket synthetically generated user id's to and actual primary user Id's generated by the database.  

Test Data Generation Stories

The following two stories, below, describe how the Test Data Mapping Design Pattern, was utilized during the population of both the User and Address tables, to solve the above described test data challenge. 


Story 1 - A Tester wants to populate a User table

A Tester wants to populate a User table with synthetic test data with the exception of the User.id column; so, the GenRocket generated unique Id must map to the primary Id generated by the database and stored in a mapping table. 


Actors

  • GenRocket
  • User Domain
  • GenericSQLInsertReceiver
  • UserScenario
  • Database
  • User Table


Action

 Within the UserScenario, for the given User.loopCount, the following actions are repeated: 

  1. GenRocket generates a row of synthetic test data for all columns in the User Domain
  2. GenRocket passes the data off to the GenericSQLInsertReceiver, with the exception of the Id column 
  3. The GenericSQLInsertReceiver prepares an SQL insert statement and sends it to the Database
  4. The  Database inserts a new row into the User table, generates and assigns a unique primary Id
  5. The Receiver requests back the primary Id
  6. The Receivers stores a namespace, the GenRocket generated Id and the primaryId into a mapping table.


Story 2 - A Tester wants to populate an Address table with referential integrity to a row in the User Table

For each User that was synthetically generated and inserted into the User database table via the GenRocket UserScenario, the Tester wants an AddressScenario to generate and store one Address into the Address table and have that Address associated to a user via the User's primaryId.  Since the actual primary Id for each row in the User table was not generated by GenRocket, a mapping table must be used to retrieve the actual Id, generated by the database, that is mapped to an Id generated by GenRocket.


Actors

  • GenRocket
  • User Domain
  • Address Domain
  • QueryEachLoopGen
  • GenericSQLInsertReceiver
  • AddressScenario
  • Database
  • Address Table

Action

Within the AddressScenario, for the given User.loopCount, the following actions are repeated:

  1. GenRocket generates a row of synthetic test data for all columns in the User Domain
  2. GenRocket traverses down to the Address Domain
  3. For the given Address.loopCount, the following actions are repeated:
    1. GenRocket gets unique Id generated from the User.id Attribute 
    2. GenRocket generates a row of synthetic test data for all columns of the Address table
    3. For the Address user_id Attribute, GenRocket uses the QueryEachLoopGen to query for the actual primary User Id that is mapped to the GenRocket generated Id from the mapping table
    4. GenRocket passes the data off to the GenericSQLInsertReceiver, with the exception of the Id column 
    5. The GenericSQLInsertReceiver prepares an SQL insert statement and sends it to the Database
    6. The Database insert a new row into the Address table, generates and assigns a unique primary Id.