Unit Testing (Advanced)
  • 15 Aug 2023
  • 5 Minutes to read
  • Dark
    Light

Unit Testing (Advanced)

  • Dark
    Light

Article summary

Overview

Unit Tests can be created using a Flow with a Rule to test data as it passes through. Using advanced techniques with Unit Tests, users can quickly and accurately check the data that is being passed through and provide a clear picture of what to test. 


Using Unit Tests on Composite Data Types

  1. In a Designer Project, click CREATE FLOW and select Flow to create a new Flow. 
  2. Click SETUP INPUT DATA and select DEFINE.
  3. In the Input Data window, enter "AccountInfo" under NAME. Enter "account" in the TYPE field and select Account. Click Save and close the window.
  4. Connect the Start step to the End step. Click Save to save changes to the Flow.

  5. Click Debug from the top action bar.
  6. In the Debugger, click Add New next to UNIT TESTS.
  7. Enter "CheckAccountField" under Test Name and click the pencil icon under the INPUT DATA - CONSTANT category next to the AccountInfo field.
     
  8. Select admin@decisions.com and click PICK.
     
  9. Click Save to save the Unit Test.
  10. Add a second Unit Test. Configure this test to use another account's email address.
  11. Edit the Rule for each Unit Test by clicking EDIT [Name of Unit Test] RULE under the [UNIT TEST DATA] category.
  12. Configure the Rules to state "if AccountInfo.EmailAddress Contains admin". Click Save and close the Rule Designer.
  13. Save the Rules. Click Run All next to UNIT TESTS to run all Unit Tests listed. The results will display which tests evaluated true (Success) or false (Failure).

Flow As Data Source

Users can also dynamically map in Flow Input Data as a Data Source for Unit Testing. 

  1. From the Debugger, add a new Unit Test.
  2. Click EDIT UNIT TEST RULE and configure the Rule to state if "AccountInfo.EmailAddress Contains decisions". Click Save and close the Rule Designer.
     
  3. In the Debugger, under UNIT TESTS > DATA SOURCE FOR UNIT TEST RULE, select From Flow. Under FLOW AS DATA SOURCE click EDIT FLOW AS INPUTS.
     
  4. In the Flow Designer, attach a Create Data step to the Start step. On the Properties panel, under DATA > Data to Create, select SHOW EDITOR.  
    Note on Flow Configuration
    The Create Data step is not required as it is only being used for example purposes. Any Flow logic that Outputs Data may be implemented to create dynamic Source Data for a Unit Test.

  5. Enter "User" under NAME and select Account as the TYPE. Click Save and close the window.
     
  6. Configure an input value for the User field by clicking the pencil icon and choosing an account.
  7. Add Connect the Done path to the End step. Select the End step. On the Properties panel, change the mapping type of Account Info to User.
      
  8. Click Save and close the Flow.  
  9. Save the Unit Test, then click Run All. 

Using Unit Tests with Step Simulation Options

Running a Unit Test on a specified step is called Step Simulation. Step Simulation can be specified on a step or on a specific direction in a Flow.

  1. In the Flow, attach a Placeholder Step to the Start step by navigating in the Toolbox panel to the ANNOTATIONS category. On the Properties panel, under Outcomes, click ADD.
     
  2. Enter "Test Simulation" for Path then click OK.
     
  3. Connect the Done path to the End Step. 
  4. Add another End step from the Toolbox panel and name the step. 
  5. Connect the Test Simulation path to the newly added End step.
  6. Select the Placeholder Step and navigate to the TESTING AND SIMULATION category on the Properties panel.
  7. Under Use Simulation Behavior, select InUnitTests to run the Simulation Behavior in the Debugger. This will then display a yellow S icon on the step to mark that it is using a Simulation Behavior. 
    Simulation BehaviorDescription
    InDebuggerRun the test in the Debugger on the selected pathway
    InProductionRun the test at Production on the selected pathway
    InUnitTestsRun the Unit Tests in the Flow on the selected pathway

  8. Under Simulation Selected Path, expand the dropdown and select the Test Simulation to run the Simulation behavior on that specific path.
     
  9. Check the Run Unit Test Rule box, then click EDIT PLACEHOLDER STEP 1 UNIT TEST RULE to define the Unit Test Rule that will be run on the selected path.
  10. Define the Rule to state "if Account.EmailAddress Contains admin". Click Save and close the Rule.  
  11. Click Debug.
  12. Under UNIT TESTS, select the CheckAccountField Unit Test and Run the Unit Test. If the Unit Test evaluates False the Flow will stop in the Debugger. If the Unit test evaluates True the Flow will continue to deploy in the Debugger.



Creating a Unit Test Completion Notification Flow

The Flow to Run After Unit Tests Execution setting allows users to assign a specific Unit Test Completion Notification Flow to start either daily at a set time, after saving the project associated Flow or Rule, or after importing the Flow or Rule into an environment. When initialized, this Flow sends an email notification to the specified account with unit test failures and successes. When testing specific scenarios, the use of the Unit Test Completion Notification Flow helps pinpoint errors soon after it initially occurs. 

  1.  In a Designer Project, select CREATE FLOW. Select Advanced and select Unit Test Completion Notification Flow.
  2.  Attach a Send Email step from the Toolbox and connect it to the Start and End steps
  3.  Configure the Send Email step to connect to desired email server's specifications. Debug the Flow and, upon successfully receiving the email, close the Flow Designer.
  4.  In the Studio navigate to Settings > Designer Studio Settings > Run Unit Tests to view the Flow To Run After Unit Tests Execution setting. Select PICK and choose the created Flow.
  5.  Select the interval to run the Notification Flow. For this example, the After Save option is selected. Enter an email address and click SAVE.
     
  6. Check the inbox of the specified receiving email account. An email reporting all project-associated Unit Tests along with individual success and failure information will appear.



Using Production Data for Unit Tests

To use real production data as a basis for unit tests, use the Save Sample Data step. Add the step to a Flow generating the desired data and it will be available in the Unit Test screen in the Debugger.

PropertyDescription
CategoryThis is used as the name of the Unit Test within the Debugger
FolderThe FolderId of the Decisions Folder that will hold the saved data. This must be set up first.
Sample DescriptionThe description of the recorded sample data.
Sample NameThis is the name the data will be saved as within the Folder, and what will appear when looking for data to run under the Category name in the Debugger.





For further information on the Portal, visit the Decisions Forum.



Was this article helpful?