Unit Testing (Advanced)
  • 28 Jul 2022
  • 6 Minutes to read
  • Dark
    Light

Unit Testing (Advanced)

  • Dark
    Light

Overview

Unit Tests can be used using various techniques within Decisions Designer Studio. Unit Tests can be created using a Flow and a Rule to test data as it passes through. Advanced Unit Tests have additional advantages that help to quickly and accurately check the data being passed through and provide a clear picture of what a user may be looking to test. The following document demonstrates advanced techniques of using the Unit Test utility in Decisions.

Prerequisite
To start with the Unit Test utility, please go through the Unit Tests Overview (Simple Flow) document first.

This document demonstrates the advantages of using Unit Tests on Composite Data Types, Step Simulation Options, and Running Unit Test Rules before any step in the Flow.


Composite Data Types

Building the Flow

  1. CREATE a new Flow in a Designer Folder.
  2. From the Flow Designer, click the SETUP INPUT DATA button under the top Action bar, then click DEFINE.
  3. In the Input Data dialog, create a Name the Input and define the Type. For this example search for Accounts in the search bar and select Account [DecisonsFramework].
  4. Save the Input Data, then close with X.
  5. Connect the Start step to the End step in the Flow. Save the Flow, then close if desired.

Debug

  1. Select the Debug link from the top Action bar. 
  2. In the Debugger, add a New Unit Test by selecting Add New next to Unit Tests.
  3. Give the Unit Test a Test Name (CheckAccountField).
  4. Select the Edit Settings button (which appears as a pencil) on the right under Input Data. 
  5. Pick or Define an existing Account(admin@decisoins.com).
  6. Click Save to save the Unit Test.


  7. Add a second Unit Test and choose different INPUT DATA. This Unit Test is named CheckEmailTest and uses an account for a different email address.



Rule

Edit each Unit Test and create a Rule that checks for Account EmailAddress Contains Admin. The example sets up a Rule that checks for admin in the Account Email Address. 

  1. In the Rule Designer write a Rule that can evaluate any desirable field of the Composite Data Type. This Rule will use the pick Email Address field from the Account Input as an example.
    The Rule states: If the Account.EmailAddress Contains admin (if the Unit test passes, the Rule will evaluate True if the Unit Test fails, the Rule will evaluate False).


  2. Save and close the Rule.
  3. Save the Unit Test rule and close the Debugger and navigate back to the Flow Designer.
  4. Select the End step, and under Data and Output, select Show Editor.
  5. Create a new data definition called Account and choose String as the Type. Under Inputs next to Account, choose Select From Flow and then pick Account.


  6. Select Close to save the configuration.
  7. In the Flow Designer, select Debug
  8. Next, to Unit Tests, select Run All to run all Unit Tests. The results of the Unit Tests will display under Under Unit Tests, displaying which test was evaluated as True or False.

Flow As Data Source

As of Decisions Installations v.7.7+, users are provided the ability to dynamically map in Flow Input Data as a Data Source for Unit Testing

  1. From the Debugger, under UNIT TESTS, click Add New
  2. Under [UNIT TEST DATA], provide a Test Name
  3. Click the Edit UNIT TEST RULE button and edit the Rule as usual, then Save and close the Rule.
  4. Back in the Debugger, under UNIT TESTS > DATA SOURCE FOR UNIT TEST RULE, select From Flow
  5. Under FLOW AS DATA SOURCE, click EDIT FLOW AS INPUTS. 

  6. From the resulting Flow Designer, attach a Create Data step to the Start step. 
    Note on Flow Configuration
    The Create Data step is not required as it is only used for example purposes. Any Flow logic that Outputs Data may be implemented to create dynamic Source Data for a Unit Test.
  7. From the Create Data step's Properties, under DATA > Data to Create, select SHOW EDITOR. 
  8. Define the Data to Create according to desired/expected Input Data for the Unit Test (in this case, an Account TYPE). 
  9. Save the Data, then close via X.
  10. Back in the Flow Designer, connect the Done path to the End step. 
  11. Select the End step to navigate to the End step's Properties, then Select From Flow map the Output of the Create Data step to the End step's INPUT DATA. 
  12. Save and close the Flow. 
  13. Save the Unit Test, then Run it via the Run button (Play icon) or Run All

Step Simulation Options

Building the Flow

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. From the Flow, add a Placeholder Step from the Annotations Folder in the Toolbox tab. 
  2. Select the step to navigate to the Properties.
  3. Under Outcomes select ADD NEW.
  4. Define the Outcome definitions in the Editor.
    Name the Path "Test Simulation" then click OK
  5. Connect the Done path to the End Step. 
  6. Search for and add an End step. 
  7. Under NAME > Data, name the step.
  8. Connect the Test Simulation path to the newly added End step. 
  9. Next, select the Placeholder Step, and navigate to TESTING AND SIMULATION under the Properties tab,
  10. Denote the Use Simulation Behavior setting as InUnitTests to run the Simulation Behavior in the Debugger.
    Doing so will display a yellow S icon on the step to mark that it is using a Simulation Behavior. 

    Each option that is checked under Use Simulation Behavior will run the Flow with that behavior and on the selected pathway.

    • InDebugger: Run the test in the Debugger on the selected pathway.
    • InProduction: Run the test at Production on the selected pathway.
    • InUnitTests: Run the Unit Tests in the Flow on the selected pathway.
  11. Under Simulation Selected Path, expand the dropdown and select the Test Simulation to run the Simulation behavior on that specific path. 
  12. Toggle the Run Unit Test Rule box, then select EDIT PLACEHOLDER STEP 1 UNIT TEST RULE to define the Unit Test Rule that will be run on the selected path.
  13. Define the Rule as If Account.EmailAddress Contains admin, Then Result { Return True. 
  14. Save the Rule and close with X



Debug

  1. From the Flow Designer, select the Debug link.
  2. Under UNIT TESTS select CheckAccountField and Run the Unit Test via the play button. 
    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.
  3. Select either Rule on the left to check the results of the Unit Tests.



Creating a Unit Test Completion Notification Flow

The Flow to Run After Unit Tests Execution setting allows Designers 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 detailing unit test failures and successes. When testing specific scenarios, the Unit Completion Notification Flow helps pinpoint errors soon after it initially occurs. 

  1.  In the Decisions Studio, select CREATE FLOW. Select the Advanced tab and then select the Unit Test Completion Notification Flow.
  2.  Search for the Send Email step in 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. Test the Flow and, upon successfully receiving the email, close out of the Flow Designer.
    Need help sending emails?
    Please refer to our Send Email and Modifying an Application Servers SMTP Settings articles for further information relating to email server SMTP configurations.
  4.  In the Studio, navigate to Settings > Designer Settings > Run Unit Tests to view the Flow To Run After Unit Tests Execution setting. Select PICK and choose the Flow made prior.
  5.  Select the interval when to run the Notification Flow. For this example, the After Save option is selected.
  6. Open a Flow with Unit Tests that belong to the same project as the Unit Test Completion Notification Flow. Save the Flow and exit the Flow Designer.
  7. 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.

Was this article helpful?