Views:

Overview

Follow the steps in this article to set up a Test to check that an HTTP triggered Flow is functioning as expected.

Prerequisites

For this article you will need to have installed and configured the North52 Calculator Demo solution and set up Test Data.

Create the Test

Initial Set up

  • Navigate to the North52 App and select TestShield > Tests
  • Click New
  • On the Register tab
    • For Test Plan enter Demo Calculator (or select from the list of existing Test Plans)
    • For Test Suite enter Calculations (or select from the list of existing Test Suites)
    • For Test Case Name enter Flow HTTP Trigger
    • For Test Type select Process Shield
    • For Sync or Async select Async
    • For A(this means the test will create the test records then allow 1 minute for the Flow process to execute, then it will assess the Asserts)
  • Click Save

Assemble

On the Assemble sheet we describe the specific scenario of a feature that will be tested and outline the steps of the test using Gherkin-style syntax.

  • On the Assemble sheet, edit cell B1 to describe the Feature being tested. Enter the text: Demo Calculator
  • Double-click cell B2
    • For the Scenario, describe what is being tested - we like to use a User Story. Enter the text:
      As a User
      I want to calculate two numbers using different operators
      So that I get the right results without having to use a separate calculator
  • The next steps describe the steps of the test:
    • Select cell B6, for the Given step
      • Enter the text: A new Calculation record is created as defined in the Arrange-Calculation sheet (we'll add the Arrange-Calculation sheet after we complete the Assemble sheet)
    • Select cell B7, for the When step
      • Enter the text: the Calculation record is created and a Flow triggered by an HTTP request
    • Select cell B8, for the Then step
      • Enter the text: Flow logic is executed and saves the calculated value into the [Flow HTTP Trigger Result] field
  • Click Save

Arrange

We need to create records to which the Flow will execute on. We use the Test Data set up previously for this purpose.

  • Select the Source tab
    • Expand the Test Data node
    • Expand Test Data - Calculator 
    • Click on Calculation - the default Arrange sheet is replaced with Arrange-Calculation with Test Data pre-populated
  • Click Save

Act

The Act Sheet allows you to execute any functions after the records in the Arrange sheet(s) have been created. For this test we need to trigger a Flow via an HTTP request. 

  • Select the Act sheet
  • Select cell A4
    • Enter the text Flow HTTP Trigger - Add
  • Select cell B4
    • Expand the editor for the cell by clicking the + in the top right of the sheet
    • Select the Functions tab and search for flow
    • Click on the ExecuteMSFlowRequest function to add the function and placeholder parameter to the formula editor
    • Delete the 'url' placeholder text including the quotes
    • Select the Source tab
      • Expand xCache
      • Expand Calculator
      • Click on Calculator_FlowTriggerUrl (you will have edited this xCache record as part of the installation and configuration of the Calculator Demo solution)
    • Delete the 'body' placeholder text including the quotes and replace with the following (Parameters need to be passed to the Flow in JSON format):
        CreateJObject( 
          CreateJProperty('value1', FindRecordsValue(GetVar('Arrange-Calculation-Row-0004'), 'north52_valueone')),
          CreateJProperty('value2', FindRecordsValue(GetVar('Arrange-Calculation-Row-0004'), 'north52_valuetwo')),
          CreateJProperty('operation', FindRecordsValue(GetVar('Arrange-Calculation-Row-0004'), 'north52_operatorname')),
          CreateJProperty('recordId', FindRecordsValue(GetVar('Arrange-Calculation-Row-0004'), 'north52_calculationid'))
        )
    • The completed formula should look like this:
    • Close the cell editor
  • Select cell A5
    • Enter the text Flow HTTP Trigger - Subtract
  • Select cell B5
    • Repeat the steps for cell B4, replacing Arrange-Calculation-Row-0004 with Arrange-Calculation-Row-0005
  • Select cell A6
    • Enter the text Flow HTTP Trigger - Multiply
  • Select cell B6
    • Repeat the steps for cell B4, replacing Arrange-Calculation-Row-0004 with Arrange-Calculation-Row-0006
  • ​​​​​​​Select cell A7
    • Enter the text Flow HTTP Trigger - Divide
  • Select cell B7
    • ​​​​​​​Repeat the steps for cell B4, replacing Arrange-Calculation-Row-0004 with Arrange-Calculation-Row-0007
  • ​​​​​​​The completed Act sheet will look like this:

Assert

Once the test records have been created we need to check that the calculated values are what we expect.

  • Select the Assert sheet
  • Select cell B4
  • Select the Source tab
  • Expand the Arrange node
  • Expand Arrange-Calculation (the four rows of data are shown as nodes)
  • Expand Arrange-Calculation-Row-0004
  • Click on Flow HTTP Trigger Result
    • {Arrange-Calculation-Row-0004-Flow HTTP Trigger Result} is added to cell B4. When the Test executes it will find this value from the record created in the Arrange step.
  • Select cell C4
    • Enter the number 15 as the expected value of our calculation
  • Select cell D4
    • Enter Add as the Step Message. This will be displayed in the Test Results so that you can quickly identify what was being tested.
  • Select cell B4, and position the cursor over the bottom right corner of the cell to show the fill handle
    • Drag down 3 rows to cell B7. You will notice that the row number reference is automatically updated (Note: you could manually add each reference field from the Local Data nodes but copying the cells down is much quicker)
  • Click into cells A5, A6 and A7 to select the AssertAreEqual Assert Type
  • Select cell C5
    • Enter the numberas the expected value of our calculation
  • Select cell D5
    • Enter Subtract as the Step Message
  • ​​​​​​​Select cell C6
    • Enter the number 50 as the expected value of our calculation
  • Select cell D6
    • Enter Multiply as the Step Message
  • ​​​​​​​​​​​​​​Select cell C7
    • Enter the number as the expected value of our calculation
  • Select cell D7
    • Enter Divide as the Step Message
  • Click Save

Run the Test

The Test is now ready to be run. For this exercise we will run the Test manually - in a later exercise we'll show you how to run the Test automatically. 

  • Click the Execute Test button - represented by the lightning button in the top right of the Test editor canvas
  • Click the Execute button on the fly-out pane
  • After a few seconds the Test records will be created (a message Result: Operation Completed will be shown)
  • Wait one minute for the asynchronous workflow processes to complete and the Test Results records to be created
  • On the Source tab, click the refresh button in the top right of the tab, then expand Test Run Results
    • You will see a node with with the time of your test and the Pass/Fail results (you should have 4 passes!), expand this node
    • Expand Assert
    • Expand Row-0004
    • Expand Add
      • You will see the Actual and Expected values​, and the Assert Type:

​​​​​​​​​​​​​​​​​​​​​

You could experiment to get a failure by changing the values in the Expected Value column and running the test again.