Story

An Organization needs to generate synthetic test data for a Domain, but wants to apply business logic to ensure the right information is generated for their test data. 


The data they need to generate is for a Users who have four Attributes: name, age, type, and allowedtoVote. They need to generate the User data with the following conditions: 

  1. Users need to be given a Type (Child, Teenager, Young Adult, or Adult) based on their Age.
  2. The user can only be allowed to vote if they are 18 and up.

Test Data Rules can be used to apply the appropriate business logic for ensuring the correct Type is assigned to a generated User and that only permitted Users are actually able to vote. 


Actors

  • Project (or Project Version) - The Project Version determines what Domains and Attributes will be used for Test Data Rules.

  • Test Data Rule Set - A set of one or more Test Data Rules, which have their own Conditions and Actions. This set may be downloaded and ran with a Scenario, Scenario Chain, or Scenario Chain Set.
     
  • Test Data Rules - A rule containing one or more Conditions and Actions for selected Domains and Attributes within the Project.

  • If Condition - One or more Conditions that must be met for defined Actions to take place.

  • Then Action - One or more Actions that take place when a Condition for a Test Data Rule is met.


Setup Overview

To set up the appropriate business logic and meet the conditions described in the Story section, the following will need to be configured for this example: 

  • 1 Test Data Rule Set
  • 4 Test Data Rules


Each Test Data Rule will contain the logic for assigning a Type and allowedtoVote value based on the User's age. The logic for these rules will be set up as shown below: 


RuleLogicDescription
ChildIf (age<=12)
Then (type == child && allowedtoVote = false)
When the user's age is 12 or below, child will be assigned for the type Attribute and false will be assigned for the allowedtoVote Attribute.
TeenagerIf (age >= 13 && age <=17)
Then (type == teenager && allowedtoVote = false)
When the user's age is between 13 and 17, teenager will be assigned for the type Attribute and false will be assigned for the allowedtoVote Attribute.
Young AdultIf (age >=18 && age <=25)
Then (type == young adult && allowedtoVote = true)
When the user's age is between 18 and 25, young adult will be assigned for the type Attribute and true will be assigned for the allowedtoVote Attribute.
AdultIf (age >25)
Then (type == adult && allowedtoVote = true)
When the user's age is above 25, adult will be assigned for the type Attribute and true will be assigned for the allowedtoVote Attribute.


Test Data Rules Set Example

This example will provide a quick overview of the Project Configuration including the Domain, Attributes, Receiver, and Scenario before showing the information for setting up the Test Data Rule Set.


Project Setup

The following shows the Project setup for this example: 

  • Domain - Create a Domain titled User.


  • The global.User.loopCount should be set to 25 to create 25 total records.


  • Attributes - Four Attributes will need to be created for the User Domain. 
    • name - First name of the user.
    • age - Age of the user.
    • type - User Type (child, teenager, young adult, or adult).
    • allowedtoVote - Flag determining if the user is able to vote or not.


  • Generators and Generator Configuration- Each Attribute will require a different Generator and Generator Configuration, which is also provided below:
    • name - Use the NameGen Generator. See the image below for the configuration:

    • age - Use the RandomGen Generator. The age will be set to between 1 and 45 for users. See the image below for the configuration:

    • type - Use the ListGen Generator. For this example, only 4 list items are necessary (child, teenager, young adult, and adult). See the image below for the configuration:

    • allowedtoVote - Use the BooleanValueGen Generator. This Generator has a two values: true and false. See the image below for the configuration:


  • Receiver - Create a new Receiver for the Domain. For this example, we will use the ExcelFileReceiver for the Project. This will create an Excel file that can be opened on the local computer.


  • Scenarios - Create a Scenario for the Domain. For this example, UserScenario has been created.


To learn more about creating these items for a Project, please see the following articles: 


After these items have been configured, you will be ready to begin setting up the Test Data Rules Set, the Test Data Rules, and all Conditions/Actions.


The test data will appear as shown below prior to configuring Test Data Rules and applying Business Logic. As you can see, the type Attribute and allowedtoVote Attribute are inaccurate in comparison with the age Attribute for some user records.



Test Data Rules Setup

Next, it is time to add a Test Data Rule Set for the Project and add the four Test Data Rules with the required Conditions/Actions.


Step 1: Add a Test Data Rule Set for the Project

  • Select the appropriate Project within the Project Dashboard of the GenRocket web platform.

  • Use the Filter input field or scroll up/down to locate the Project. Click on the Project Name to select it.


  • Expand the Manage Menu option for the appropriate Project Version and then select Test Data Rules.


  • Click on Add Test Data Rule Set to create a new set.


  • Enter a Name and Description (Optional) for the Test Data Rule Set and click Save. For this example, it will be titled VotingExample.


  • The new Test Data Rule Set will appear in the table, as shown below:


    Note: Please note that "Rules" will be added to the end of the set name.


Step 2: Add the Test Data Rules to the Set

Note: Complete these steps 4 times to create 4 separate Test Data Rules: child, teenager, young adult, and adult.

  • Click on Add Test Data Rule.


  • A Name will automatically be assigned by GenRocket for the Test Data Rule.

  • The Description is optional. Click Save to finish.


  • The new Test Data Rule will appear within the table as shown below:


  • When all four rules have been created, the Test Data Rules Table will look like this:


Step 3: Configure the Conditions for each Test Data Rule

  • Select the Test Data Rule within the table to view its configuration.

  • A rule will be highlighted in blue when it is selected. For this example, rule1 will be selected.


  • Click on Add Condition to add a Condition to the selected Test Data Rule.


  • Use the drop-down menus and entry fields to configure each Test Data Rule. An image has been provided below for each of the 4 Test Data Rule Conditions:
    • rule1 - Domain is User; Attribute is age; Qualifier is <=; and Value is 12. Condition is THEN to show that if this condition is met then an action will take place.


      The Pseudo Code would be as follows:



    • rule2- This rule has two conditions that must be met. The User must be between 13 and 17. Two conditions will need to be added: 
      • Condition 1: Domain is User; Attribute is age; Qualifier is >=; and Value is 13. Condition is AND to show that another condition must be met.


      • Condition 2: Domain is User; Attribute is age; Qualifier is <=; and Value is 17. Condition is THEN to show that if this and the first condition are met, then an action will take place.


        The Pseudo Code would appear as follows:


    • rule3- This rule has two conditions that must be met. The User must be between 18 and 25. Two conditions will need to be added: 
      • Condition 1: Domain is User; Attribute is age; Qualifier is >=; and Value is 18. Condition is AND to show that another condition must be met.


      • Condition 2: Domain is User; Attribute is age; Qualifier is <=; and Value is 25. Condition is THEN to show that if this and the first condition are met, then an action will take place.


      • The Pseudo Code would appear as follows:


    • rule4 - Domain is User; Attribute is age; Qualifier is >; and Value is 25. Condition is THEN to show that if this condition is met then an action will take place.


      The Pseudo Code would appear as follows:


Step 4: Configure the Actions for each of the Test Data Rules

Each Test Data Rule will require two Actions: 

  1. Assigns the appropriate type Attribute for the user (child, teenager, young adult or adult).
  2. Assigns the appropriate allowedtoVote Attribute value to the user (true or false).


To add the first Action for a Test Data Rule, complete the following steps: 

  • Click on New Action to begin configuring an action.

     
  • In the configuration window, complete the following: 
    • Select the type Attribute.
    • Make certain Constant is chosen for the Value Type.
    • Enter a Value (child, teenager, young adult, or adult) depending on the selected Test Data Rule.

  • Click Save to save the Action.


To add the second Action to the Test Data Rule, complete the following steps: 

  • Click on New Action to begin configuring an action.


  • In the configuration window, complete the following: 
    • Select the allowedtoVote Attribute.
    • Make certain Constant is chosen for the Value Type.
    • Enter a Value (true or false) depending on the selected Test Data Rule.

  • Click Save to save the Action.


Note: These steps will need to be completed 4 times (one for each rule) to ensure the 2 Actions are added to each Test Data Rule in the set.


The completed configuration for rule1 will appear as shown below: 



The completed Pseudo Code for rule1 will appear as shown below: 



Step 5: Download the Test Data Rule Set and Scenario to Local Computer

Once all Test Data Rules have been added and the Conditions/Actions have been set up, download the Test Data Rule Set and the Scenario to your local computer. 

  • Click on the Download (Cloud) option located on the far right of the table in the Action Column to download it to your local computer.


  • Click on the Scenario within the Project Dashboard or the Domain Dashboard to view its configuration.


  • Next, click on the Download Button to download it to your local computer.


Step 6: Run the Test Data Rule Set with the Scenario

The Test Data Rule and the Scenario (or Scenario Chain/Scenario Chain Set) are ran using the command line shown at the bottom of the screen. 


The following is an example of the command line for running this examples Test Data Rule Set with a Scenario.



These values will be different depending on the name of the Test Data Rule Set and the Scenario to be run.

  • VotingExampleRules.gtdr - Name of the Test Data Rule Set to be run.
  • <ScenarioName.grs> - Name of the Scenario, Scenario Chain, or Scenario Chain Set to run.


Open a Command Terminal and set the directory to where files are downloaded from the GenRocket web platform to your local computer. 



Then replace the appropriate values within the command line. The Test Data Rule Set and Scenario Name can be changed accordingly. 



After it is run, you can open the file to view the generated test data and verify the information is correct. It will appear similar to what is shown below: 



Additional Information

For information on how to configure and manage Test Data Rule Sets, please see the following pages: