Generate an automate test
  • 18 Feb 2023
  • 1 Minute to read
  • Contributors
  • Comment
  • Dark
    Light
  • PDF

Generate an automate test

  • Comment
  • Dark
    Light
  • PDF

Article Summary

Its possible to use the logic app testing framework to generate an automated test from the run history from a previous run of a workflow.

The video below shows how to do it

This is the code snipped I used in the video to generate a test which I can then grab from the debug window.

[TestMethod]
        public void GenerateTest()
        {            
            And the logic app test manager is setup
            var logicAppTestManager = LogicAppTestManagerBuilder.Build("ShipInstruction-Processor");
            var result = logicAppTestManager.GenerateTestSample("08585264468876695176318880222CU00");

            Debug.WriteLine(result.TriggerMessage);
            Debug.WriteLine(result.TestSampleCode);
        }

In my case the generated test looked like this code below.

[TestMethod]
        public void Test()
        {
            var actionStatus = ActionStatus.Succeeded;

            //Arrange
            var workflowName = "ShipInstruction-Processor";
            var logicAppTestManager = LogicAppTestManagerBuilder.Build(workflowName);

            var request = File.ReadAllText(@"..\..\..\Features\ShipInstruction\MsTest\SampleInput.xml");

            var content = new StringContent(request, Encoding.UTF8, "text/xml");
        
            //Act
            var response = logicAppTestManager.TriggerLogicAppWithPost(content);
            logicAppTestManager.LoadWorkflowRunHistory();

            //Assert
            Assert.IsNotNull(response.WorkFlowRunId);

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

            var workflowRunStatus = logicAppTestManager.GetWorkflowRunStatus();
            Assert.AreEqual(workflowRunStatus, WorkflowRunStatus.Succeeded);

            actionStatus = logicAppTestManager.GetActionStatus("Compose_-_Convert_to_Json");
            Assert.AreEqual(actionStatus, ActionStatus.Succeeded);

            actionStatus = logicAppTestManager.GetActionStatus("Compose_-_Request_as_Json");
            Assert.AreEqual(actionStatus, ActionStatus.Succeeded);

            actionStatus = logicAppTestManager.GetActionStatus("Condition_-_Is_Petrochemical");
            Assert.AreEqual(actionStatus, ActionStatus.Succeeded);

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

            actionStatus = logicAppTestManager.GetActionStatus("HTTP_-_Lookup_Data");
            Assert.AreEqual(actionStatus, ActionStatus.Succeeded);

            actionStatus = logicAppTestManager.GetActionStatus("Parse_JSON_-_Ship_Event");
            Assert.AreEqual(actionStatus, ActionStatus.Succeeded);

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

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

        }

A couple of points to note on this are:

  • There is an option when you use the generate test operation to let the framework include assertions for skipped actions. By default they are ignored from the generated code.

Was this article helpful?