Unit Testing (Advanced)
- Updated on 13 Mar 2019
- 4 minutes to read
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 .
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].
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 aName (CheckAccountField) and select the Input Data settings button on the right under Input Data. Next, Pick or Define an existing Account (email@example.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: firstname.lastname@example.org .
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.
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).
Select Run All to run all Unit Test's created. Next, Save, close the Unit Test and navigate back to the Flow designer.
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.
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.
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.
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, selectRun Unit Test Rule. Under Unit Test Rule selectEdit to edit the rule. In the Flow, Name the test and pick Account.
Next, build the Rule that will run on thePlaceholder Step.
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.
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.