Unit Tests Advanced

Last Updated: 07/19/2016 Introduced in Verision: 3.5

This document demonstrates advanced techniques of using Unit Test utility in Decisions Designer. 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 Complex Data Types, Step Simulation Options, and Running Unit Test Rules before any step in the Flow.

Example:

We begin in the Designer Folder with clicking Create Flow button on the Folder Actions Panel.

createFlow

Then, we Name the Flow and click Create to proceed to the Flow Designer.

nameFlow

First, we are going to add a complex data type as a Flow Input. We select start step on the workspace and click Add New Flow Input Data. Then, we Name the Variable and define its type of Account.

addAccountFlowInput

Next, we connect Start Step to the End Step in our Flow and click Unit Test link on the Top Panel of the Flow Designer.

addUnitTest

We Name our Unit Test and press Account Flow Input Data picker.

pickAccount

Then, we pick an existing Account and click Ok.

selectAccount

Next, we are going to build a Rule for this Unit Test.

createRule

When Rule Designer opens we click Add New Rule Step.

addRuleStep

Because we have a complex Account Flow Input Data, we can see an Account input and use in the Rule Designer. Moreover, we are able to write a Rule to evaluate any desirable field of the Complex Data Type. In this Example we are going to pick Email Address field from the Account input.

pickEmailAddress

Then, we select Contains verb…

emailAddressContains

Finally, we check if Email Address contains Constant ‘admin value which will fail our Unit Test because for this Unit Test we have selected an Account that has user@decisions.com Email Address.

provideConstantEmailContains

Our Rule is completed. We can save it and close Rule Designer.

ruleCompleted

Next, we Save our Unit Test…

saveUnitTest

In the Flow Unit Tests window we can click Run All to run a Unit Test that we have just created.

runTest

And our Unit Test fails…

testFailed

Next, we are going to update our Flow. We Add New Flow Output at the End Step by simply picking Account Flow Input Data.

pickAccountOutput

Then, we click Unit Test. In the Flow Unit Tests window we click Create New, Name Test, and pick the same Account that we picked for the first Unit Test. Next, we start building our Rule.

addSecondUnitTest

In the Rule Designer we start building a Rule Step by picking Email Address field from the Outcome_Done_Account Data.

pickOutcomeEmail

Then, we build our Rule in the same manner we did for the first Unit Test in this tutorial. When finished, we can save the Rule and close Rule Designer.

ruleSecondCompleted

Back in the Flow Unit Tests window we Save second Unit Test and Run All tests.

runAllTwoTests

As we expected, both Unit Tests fail…

twoTestsFailed

Next, we are going to see the advantages of 3.5 Decisions Unit Test utility compared to 3.2 Decisions Unit Test. We are going to update our Flow with the Step that will change our Complex Data Flow Input (Account). Between Start and End Steps in our Flow we add UpdateAccount Step from Integrations > All Integrations > Internal Services > Account Service category.

addUpdateAccount

Then, we select UpdateAccount Step on the workspace and click Show Mapping Editor.

showMappingForUpdateAcc

In the Mapping Editor we pick Build Data Mapping type for the account input into the Step.

buildDataForUpdateAcc

Then, we map all data from the Account Flow Input to the account UpdateAccount fields except EmailAddress. For the EmailAddress field we Constantly change it to userAdmin@decisions.com. Save and close Mapping Editor when finished.

mappingForUpdateDone

Back in the Flow Designer we click Unit Test and in the Flow Unit Tests window we Run All our saved Unit Tests.

runAllTwoTestsUpdateAcc

This time the First Test fails and the Second Test passes. Even though we Output the same Account, it was changed in the Flow and satisfies conditions of the second Unit Test.

secondTestPasses

Next, we are going to create similar Testing case in Decisions 3.2 and see how it differs. We created a simple Flow that has acc (Account) Flow Input and we just pick this Data for the Flow Output on the End Step.

32AccNoUpdatesFlow

Then, we click Debug Flow and it asks us to create a Unit Test because our Flow has undefined Flow Input Data. We Name the Unit Test, Expect it to Pass and using Input and Output Data pickers

pickAccsUnitTest32

We pick the same Account and Save Unit Test.

unitTest32Save

Next, in Flow Unit Tests window we click Run All…

runFirstTest32

Obviously, our Test passes because we picked the same Account for the Input and Output.

firstTestPassed32

Then, we update our Flow with UpdateAccount Step to change FirstName field of the Flow Input Account.

updateAccount32

Then, we click Debug Flow and in the Flow Unit Tests window we click Run All to run our saved Unit Test.

runTest32Updated

The Test passes again even with the changes made to our Account because we were not able to apply the Rule to check a particular Account’s field.

updatedTest32Passes

Next, back in Decisions 3.5 we are going to look at the case where we have a Form in our Flow and need to run Unit Tests. We add Show Form step from Favorites category after UpdateAccount in our Flow.

addShowForm

In the resulting window we Name our Form and click Create to proceed to the Form Designer.

createForm

Our Form has a TextBox and a Button. When finished designing our Form, we can save it and close Form Designer.

formDesign

Back in the Flow Designer we define a Constant Input for the TextBox on the Form.

constantFormInput

Then, we connect Form Step to the End Step in our Flow and click Unit Test.

unitTestWithForm

In Flow Unit Tests window we click Run All…

runAllTests

First Unit Test passes because our Account’s Email Address was changed in the previous Run and now it satisfies the conditions of the first Unit Test. But second Unit Test fails… It fails because our Unit Test cannot complete the Form and get to the End Step. As a result, all Unit Tests that perform checks after the Form Step will fail.

secondTestWithFormFails

Next, we are going to demonstrate how to fix this. On the workspace we select our Form Step. If we scroll down the Step Settings, we should see Testing and Simulation options. This set of options available for each step in Decisions. We expand Testing and Simulation category to check what options we get here…

optionsForFormStep

Handle In Debugger:

  • OnlyOnce (output Debug Info once: if we have a step in a loop the info about first step execution only shown)
  • EveryTime (output Debug info for each step run in current Flow execution)
  • Never (Debug info for the step will not be shown in Debugger)
  • Default (set in System > Settings > Designer Studio Settings > Flow Debug Default)

handleInDebuggerOptionsForFormStep

Next, in Use Simulation Behavior we can set Simulation Behavior for this step InDebugger, InProduction, and InUnitTests. For this example we need to set Simulation Behavior for InUnitTests. After we check InUnitTests check-box we need to define Simulation Data because our Form has an input TextBox that needs to be defined for Simulation.

simulInUnitTests

We simply set it to some Constant value. In Simulation Selected Path we can set an Outcome for the step if it is in Simulation mode. For instance, if our Form had two Action Buttons we would have been able to select which Outcome Path our Flow takes if the Form Step in Simulation mode.

simulatioDataSet

 

Then, we click Unit Test and in the Flow Unit Tests window Run All…

runAllWithFormSimulation

This time both Tests pass because Unit Test utility was able to simulate Form Step.

formInSimulationTestPassed

Another powerful feature of Unit Test utility is that we can run our custom Rules before any Step in our Flow. This means that we can check what we should expect at certain points of Flow execution. To use this feature we need to select a Step on the workspace, in the Step options check Run Unit Test Rule check-box. Then we will see an option to build or edit a Rule.

createUnitTestBeforeStep

In this example we build a simple Rule that checks if the Output from UpdateAccount step is null. Then, we save the Rule and close Rule Designer.

ruleBeforeFormStep

Back in the Flow Designer we click Unit Test. In the resulting window we click Run All.

runUnitTestsWithRuleBeforeSep

Both Unit Tests fail because Unit Test for our Form Step failed.

bothTestFailedCausedBeforeStepRule

 

 

 

 

 

 

Additional Resources