Running Unit Tests on a Flow
- Updated on 09 May 2013
- 3 minutes to read
You can run unit tests on flows from the Flow Designer . Unit tests run like regular tests in the debugger, but they let you define boilerplate flow input data (so you don't have to enter it manually each time you want to run a test). This assumes your flow has input data; if not, the unit test option will not appear in the debugger. Using a unit test is especially helpful during development of a flow that uses many input data.
Unit tests also let you define an output rule for evaluating flow output data. Again, this assumes your flow has output data; if not you can ignore it. This lets you evaluate whether your flow is returning the output data you expect when you've run it with a certain set of input data.
To run a unit test on a flow open in the Flow Designer, click Debug Flow in the top bar. If the flow has input data, you will be prompted to enter it in the right panel and given the option to save it as a unit test input.
Our example flow will add 10 to any number and output the result. For this example, we will define two test scenarios.
In the Decisions Studio , we will begin by creating a new flow in a Designer Folder. For more information on creating a flow, see Creating Your First Flow . For this example we name it AdditionFlow .
First, we will click the green Start Step of our flow and, in the Properties tab on the right under Flow Data , click Add New .
In the Add Flow Input Data pop-up, we define an input called "Number" with a type of Int32 and click OK.
Back in the Flow Designer, in the Steps tab on the right under Data > Numbers, we drag an Add step onto the workspace.
This step will take the Int32 input data we created - "Number" - and add 10 to it (10 is an arbitrary value we've chosen for this example). To configure this Add step, first click on it, then in the Properties tab on the right side click Edit Input Mapping.
We configure the mapping editor as follows:
Next, we will click and drag the outcome path of the Add step to the End Step.
When we test this flow we will want to see and be able to evaluate the output data from the Add step. To do this we need to create output data.
To do this, click on the End Step and, in the Properties tab on the right under the Output section, click Show Editor.
In the resulting Data Definitions pop-up, we create define an output called "NumberOut" with a type of Int32 and map our original data - "Number" - to it. Click Close when finished.
We're done with the flow. To run a unit test on it, click Debug Flow in the top bar. In the Edit Unit Test Field, Type the Test Name, the INPUT_Number to 5, then click the Edit link under the Test Result Evaluation Rule .
The resulting Rule should say the following to have a Failed Test returned as Passed:
Note: This rule "returns the opposite result"
Next we establish a new Test with a new Rule to return a true result.
Here, our INPUT_Number is 5 and we expect an outcome of 15. The Rule will evaluate this result as True and Pass the Unit Test.
To run our tests, we will click the Run All button. Our first two tests will have a Successful result. To run a test individually, we can use the play button on the right side of each unit test entry. To remove or modify, use the right hand side field.