How to define tests on FlowEngine flows?

In this tutorial, we will show you how to define test cases inside FlowEngine, without the need of copying a flow, changing node’s links or making any changes at all on your production flows.

Instructions

  1. Install “node-red-contrib-flow-asserter”. Go to the “Pallete Manager” menu


    Then go to the install tab and search for “node-red-contrib-flow-asserter“:

     

  2. Define what your flow will look like. Just create your flow as needed. For instance, create a flow that inserts data into an Ontology:

     

  3. Add the “flow-asseter out node”: This node will define where in the flow the testing evaluation will take place. In this example, you will want to evaluate if the insertion has been successfully or not, so place it after the INSERT node.


    If the test is launched, the message will not be sent to the next node. Instead it will be sent to the lower output of the “flow-asserter in“ node. When executing the flow in regular conditions (instead of tested), this node will be ignored.

  4. Define your test cases by adding the “flow-asserter in” node.


    This node has two outputs. The upper one, which is connected to the flow to be tested, generates a message with the test case. The lower one will show the result of each test. Inside the node, you can define as many test cases as needed:


    The “input” field represents the msg.payload sent to the flow in the msg.payload for the test. The two remaining fields define how to compare the result of the msg.payload on the “flow-asserter out” node to determine whether the test was successful or not. In this example, set two tests.

    1. Test 0: Sends a valid ontology instance to be inserted, so you can expect the insert node to return some ids. In that case the check will be that the result of the insertion must have the string “ids”.

    2. Test 1: Sends an empty ontology instance, that will make the insertion to fail. We will expect the msg.payload to contain the string “Error processing data”.

    3. Test 1: Submits an empty ontology instance, which will cause the insertion process to fail. As a check for the failure, look for the response to contain the string “Error processing data”. We must also link this node to the “flow-asserter out” by selecting its id in the “flow-asserter out node” field.

  5. Save the changes by clicking on the “Deploy” button.

     

  6. Check bby running the tests. By clicking on the left tab of the “flow-asserter in” button, you will launch the different test cases:


    Each test case generates a message in the flow, the results of which we can see in the second output:



    You can even change the output to insert the test result into your user's audit ontology:



    and you can see the results, for example, from the Query Tool:




  7. Test normal execution. If you launch the flow normally, the test nodes will be ignored.

 

You can find more information about the node HERE.

 

Bear in mind that each node executed with the tests will persist its operation as if it were a normal execution.

Related articles (in Spanish):

 

Filter by label

There are no items with the selected labels at this time.