Unit Testing (Advanced)
  • Updated on 13 Mar 2019
  • 4 minutes to read
  • Print
  • Dark
    Light

Unit Testing (Advanced)

  • Print
  • Dark
    Light

Unit Tests can be used using various techniques within Decisions designer studio. Unit Test's can be created using a flow and a rule to test data as it passes through. AdvancedUnit Test's 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 designer .
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 theStart Step in the Flow designer and choose Show Editor in the Properties Tab to add a new flow Input Data. In the Data Definitions Editor create a dataName and define theType . For this example search for accounts in the search bar and select Account [DecisonsFramework].
2018-09-04_164546.jpg

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.
2018-08-31_164001.jpg

In the debugger add a New Unit Test by selecting Add New next to Unit Tests.
2018-09-06_151235.jpg

Give the Unit Test aName (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.
2018-09-06_150943.jpg

Add a second Unit Test and choose a different Input Data. This Unit Test is named CheckEmailTest and uses Account: user@decisions.com
2018-09-05_115153.jpg

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 eachUnit Test.
2018-09-04_144220.jpg

In the Rule designer write a rule that can evaluate any desirable field of theComposite Data Type. This rule will use the pickEmail Address field from the Account input as the 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).

2018-09-04_154154.jpg

Select Run All to run all Unit Test's created. Next, Save, close the Unit Test and navigate back to the Flow designer.
2018-09-05_134453.jpg

Select theEnd Step and under Data and  Output selectShow Editor. Create a new data definition called**(Account)** and then choose String as the Type**.** Under Inputs next toAccount choose Select From Flow and then pick Account.
2018-09-04_152045.jpg

In the Flow designer, selectDebug . 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.
2018-09-05_140005.jpg

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

Step Simulation Options

In the Flow navigate to thePlaceholder Step and in theProperties Tab Add Simulation Selected Paths . Under Outcome Definition and under Outcomes select Add New to Add a new outcome/pathway. 
2018-09-05_151645.jpg

Define the Outcome definitions in the editor.
2018-09-06_131218.jpg

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.
2018-09-06_113934.jpg

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.

2018-09-06_115255.jpg

Begin in the Unit Test Flow then, selectRun Unit Test Rule. Under Unit Test Rule selectEdit to edit the rule. In the Flow, Name the test and pick Account.
2018-09-06_125942.jpg

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

2018-09-06_133629.jpg

In the Flow designer select Debug to open up theUnit Test options. Under Unit Tests on the left chooseCheckAccoutFeild and then Run the Unit Test.
2018-09-04_155244.jpg

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.
2018-09-04_155122.jpg

This completes the example for advanced Unit Testing.

Was this article helpful?