Microsoft recently announced a unit testing framework for Logic App Standard which is really cool and helps plug a gap which we had in Logic App Consumption where you could not run your workflow on your developer machine and check your code works without all of the dependencies on stuff in Azure.
The unit testing framework is here if you havent seen it:
https://github.com/Azure/logicapps/tree/994b3d91d57f7ce88b7d331734dcc03fe54c5816/LogicAppsSampleTestFramework
Pluging this gap will help improve the quality of the logic app solutions people build I am sure, but there is still a gap for Logic App Standard that we cant easily do the automated integration testing that we do with Logic App Consumption.
Why do we want integration testing
Now that we have unit testing you might be wondering why we still need that integration testing. There is a pretty interesting article here which talks about the differences in those concepts quite well.
https://medium.com/@yapaxinl/inherited-backend-bdd-integration-testing-c1afe083c8d7
In my opinion for enterprise integration scenarios the automated integration testing is actually more important than the unit testing. Ideally though you should do both.
Unit testing with the self hosted framework will make it easier to run lots of tests and scenarios but what happens when you actually deploy your workflow. Will they still run as expected, what happens when your connect to real systems and many other considerations come into play.
You may have seen my previous content about SpecFlow testing for Logic Apps and I am a huge fan of the way this approach allows you to lower the total cost of ownership of your solution by creating self documenting behaviour driven integration tests. I think this approach will make your life so much easier and I have wanted to be able to do this with Logic App Standard for ages and hence I have setup this framework to help myself and hopefully you will find it useful too.
Logic App Test Framework
The code for this framework is on github at the following location:
https://github.com/michaelstephensonuk/IntegrationPlaybook-LogicApp-Standard-Testing
The package can be added from nuget at the following location:
https://www.nuget.org/packages/IPB.LogicApp.Standard.Testing
The aim of the framework is to allow you to do the following:
- Connect to a workflow in logic app standard
- Get the call back url to trigger the workflow from a test
- Check the results of the workflow that ran
- Check the actions from the workflow run history
- Make it easy to plug into automated testing frameworks that logic app developers might use
- Make it easy to plug into specflow for BDD for logic apps
If we take a look at a simple Logic App that we want to test as shown below:
I can write the below code to test this Logic App.
[TestMethod]
public void GreenPath()
{
var workflowName = "Hello-World-1";
var logicAppTestManager = LogicAppTestManagerBuilder.Build(workflowName);
//I have a message to send to the workflow
var message = new Dictionary<string, object>();
message.Add("first_name", "mike");
message.Add("last_name", "stephenson");
var requestJson = JsonConvert.SerializeObject(message);
//Send a message to the workflow
var content = new StringContent(requestJson, Encoding.UTF8, "application/json");
var workflowResponse = logicAppTestManager.TriggerLogicAppWithPost(content);
//If we get a run id then we know the logic app got the message
Assert.IsNotNull(workflowResponse.WorkFlowRunId);
//If the logic app started running we can load the run history at this point to start checking it later
logicAppTestManager.LoadWorkflowRunHistory();
//We can check the trigger status was successful
var triggerStatus = logicAppTestManager.GetTriggerStatus();
Assert.AreEqual(triggerStatus, TriggerStatus.Succeeded);
//Check that an action was successful
var actionStatus = logicAppTestManager.GetActionStatus("Compose - Log Message Received");
Assert.AreEqual(actionStatus, ActionStatus.Succeeded);
//Check that another action was successful
actionStatus = logicAppTestManager.GetActionStatus("Response");
Assert.AreEqual(actionStatus, ActionStatus.Succeeded);
//Check the workflow run was successful
var workflowRunStatus = logicAppTestManager.GetWorkflowRunStatus();
Assert.AreEqual(WorkflowRunStatus.Succeeded, workflowRunStatus);
}
It is then easy to start using the code within specflow and you can see in GitHub on the below link an example of using Specflow to Test this same logic app.
Feature File:
Steps:
I hope this will help you to develop great solutions with Logic App Standard. Combining automated unit testing and automated integration testing is where we have wanted to be for ages.
In the future ill try to add some videos about it in the integration playbook:
https://www.integration-playbook.io/docs/integration-testing