Local Testing 101
  • 30 Nov 2022
  • 1 Minute to read
  • Contributors
  • Comment
  • Dark
    Light
  • PDF

Local Testing 101

  • Comment
  • Dark
    Light
  • PDF

Article summary

In the local unit testing you are using IPB.LogicApp.Standard.Testing.Local.
You will use the WorkflowTestHost class in the framework which you will setup by pointing it to a folder containing your workflow definitions and the configuration files and then you run the test host which will behind the scenes spin up func.exe running your workflow and it will then allow you to test it as shown below.

var workflowToTestName = "Echo";
var workflowTestHostBuilder = new WorkflowTestHostBuilder();
workflowTestHostBuilder.Workflows.Add(workflowToTestName);
                        
using (var workflowTestHost = workflowTestHostBuilder.LoadAndBuild())
{
    //Add your code to test the workflow here
}

You will then setup the LogicAppTestManager to act as a client to call your workflow.

//Create the test manager to act as the client for testing the logic app
var logicAppTestManager = new LogicAppTestManager(new LogicAppTestManagerArgs
{
    WorkflowName = workflowToTestName
});
logicAppTestManager.Setup();

You can then trigger your workflow like below (assuming it has an HTTP trigger)

var content = new StringContent("{}", Encoding.UTF8, "application/json");
var response = logicAppTestManager.TriggerLogicAppWithPost(content);

You can then load the workflow run history and make assertions such as if the trigger was successful

logicAppTestManager.LoadWorkflowRunHistory();

var triggerStatus = logicAppTestManager.GetTriggerStatus();
Assert.AreEqual(triggerStatus, TriggerStatus.Succeeded);

You can also test the results of actions

var actionStatus = logicAppTestManager.GetActionStatus("Response");
Assert.AreEqual(actionStatus, ActionStatus.Succeeded);

The aim is to assert the expected actions for the result you expect which allows you to validate the workflow ran as expected for the scenario you want

Example

The below link is to one of the tests within the github repo where it will give an example of using the local testing

https://github.com/michaelstephensonuk/IntegrationPlaybook-LogicApp-Standard-Testing/blob/3f1120002cfa3e081e9eb51b331df69694b1693e/LogicApp.Testing.Example/Features/LocalWorkflow/Tests.cs#L27


Was this article helpful?