Unit Testing (Advanced)
  • 27 Jul 2022
  • 5 Minutes to read
  • Dark
    Light
  This documentation version is deprecated, please click here for the latest version.

Unit Testing (Advanced)

  • Dark
    Light

Article summary

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 advantages that help to quickly and accurately check the data being passed through and provide a clear picture of what you may be looking to test. This document demonstrates advanced techniques of using Unit Test utility in Decisions.

Prerequisite
To start with Unit Test utility please go through 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.

Example

Composite Data Types

Begin by starting from the flow designer. Select the Start step in the Flow designer and choose Show Editor in the Properties tab to add a new flow Input Data. In the Data Definitions dialog create a data name and define the Type. For this example search for accounts in the search bar and select Account [DecisonsFramework].

Next, connect the Start step to the End step in the Flow and select Debug located on the top of the flow designer on the action panel to open up a Unit Test.

In the debugger add a New Unit Test by selecting Add New next to Unit Tests.


Give the Unit Test a name (CheckAccountField) and select the Input Data settings button on the right under Input Data.  Next, Pick or Define an existing Account (admin@decisoins.com)  add a description and select Define to save a close.

Add a second Unit Test and choose a different Input Data. This Unit Test is named CheckEmailTest and uses Account: user@decisions.com.

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. Select 'Edit' under the Test Result Evaluation Rule to add a rule to each Unit Test.

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).

Select Run All to run all Unit Tests created. Next, save and close the Unit Test and navigate back to the Flow Designer.

Select the End step and under Data and Output select Show Editor. Create a new data definition called Account and then choose String as the Type. Under Inputs next to Account choose Select From Flow and then pick Account.


In the Flow designer, select Debug. 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 evaluated as true or false.

This completes the example of setting up Unit Tests for Composite Data Types.

Step Simulation Options

In the Flow navigate to the Placeholder Step and in the Properties tab Add Simulation Selected Paths. Under Outcome Definition and under Outcomes select Add New to add a new outcome/pathway.

Define the Outcome definitions in the editor.


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. Start with the Unit Test Flow, add a Placeholder Step and connect the pathways.

Testing and Simulation (Use Simulation Behavior)

Each option that is checked under 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.
  • InUnit Tests: Run the Unit Tests in the flow on the selected pathway.

Simulation Selected Path

  • Choose the path in the drop-down to run a Unit Test or a Unit Test Rule.

Run Unit Test Rule

  • Checking the box runs aUnit Test Rule on a specific Test. The Unit Test Rule can be created by selecting edit underneath the specified Step. The Unit Test Rule runs before the step.

Begin in the Unit Test Flow then, select Run Unit Test Rule. Under Unit Test Rule select Edit to edit the rule. In the Flow, Name the test and pick Account.

Next, build the Rule that will run on the Placeholder Step.

In the Flow designer select Debug to open up the Unit Test options. Under Unit Tests on the left choose CheckAccoutFeild and then 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.

This completes the example for advanced Unit Testing.


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, use of 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 Sending Email from a Flow 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. A email reporting all project associated Unit Tests along with individual success and failure information will appear.

Was this article helpful?