Skip to content

Commit 4cfc667

Browse files
authored
Merge pull request #8 from ecfan/patch-1
Editorial pass and screenshot updates
2 parents d4f8e9e + 3a5a13d commit 4cfc667

File tree

5 files changed

+66
-54
lines changed

5 files changed

+66
-54
lines changed

articles/logic-apps/create-unit-tests-standard-workflow-definitions-visual-studio-code.md

Lines changed: 66 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,97 @@
11
---
2-
title: Create unit tests from a Standard workflow definition in Azure Logic Apps with Visual Studio Code (Preview)
3-
description: Create a Logic Apps Standard workflows based on a workflow definition,
2+
title: Create Unit Tests from Standard Workflows with Visual Studio Code
3+
description: Create unit tests from Standard workflow definitions in Azure Logic Apps by using Visual Studio Code.
44
services: logic-apps
55
ms.suite: integration
6+
author: wsilveiranz
7+
ms.author: wsilveira
68
ms.reviewer: estfan, azla
79
ms.topic: how-to
810
ms.date: 04/14/2025
11+
# Customer intent: As logic app developer, I want to learn how to create a unit test that mocks the operations and outputs from a Standard workflow definition in Azure Logic Apps with Visual Studio Code.
912
---
1013

11-
# Create unit tests from a Standard workflow definition in Azure Logic Apps with Visual Studio Code (Preview)
14+
# Create unit tests from Standard workflow definitions in Azure Logic Apps with Visual Studio Code (Preview)
1215

1316
> [!NOTE]
1417
>
1518
> This capability is in preview and is subject to the [**Supplemental Terms of Use for Microsoft Azure Previews**](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
1619
17-
Unit testing is an essential practice that keeps your app or solution reliable and accurate during the software development lifecycle. Unit tests also help you efficiently and systematically validate the key components in your solution.
20+
Unit testing is an essential practice that keeps your app or solution reliable and accurate throughout the software development lifecycle. Unit tests help you efficiently and systematically validate the key components in your solution.
1821

19-
For Standard logic app workflows, you can create unit tests by using Visual Studio Code and the Azure Logic Apps (Standard) extension. This capability lets you use existing workflows to create unit tests and tailor them to scenarios supported by your logic apps solution. This approach lets you test your workflows without requiring interactions with the connected services or systems and provides the following benefits:
22+
For Standard logic app workflows, you can create unit tests by using Visual Studio Code and the Azure Logic Apps (Standard) extension. This capability lets you use workflow definitions to create unit tests and tailor them to scenarios supported by your logic app solution - all without needing connections to any external services, systems, or APIs. This approach lets you test your workflows without having to interact with external services, systems, or APIs and provides the following benefits:
2023

21-
- Improve workflow quality by identifying and addressing potential issues before you deploy to other environments.
22-
- Streamline unit test integration with your development process, while ensuring consistent and accurate workflow behavior.
24+
- Improve workflow quality by identifying and addressing potential issues before you deploy to other environments.
2325

24-
This guide shows how to create a unit test from a workflow definition to mock external actions, while preserving the existing workflow logic. When you create a unit test for a workflow, your project includes two sets of files:
26+
- Streamline unit test integration with your development process, while ensuring consistent and accurate workflow behavior.
2527

26-
- A folder that contains strongly typed classes for each mockable action in your workflow.
27-
- A folder for each unit test definition, which includes the following files:
28-
- A JSON file that represents the generated mocked operations in your workflow.
29-
- A C\# file that contains a sample class and methods where you set up your own assertions, confirm that the workflow behaves as expected, and make sure that the workflow behaves reliably and predictably in your larger Azure ecosystem.
28+
This guide shows how to create a unit test definition from a workflow. This definition mocks the external calls from each workflow operation without changing the workflow logic. When you create a unit test for a workflow, you get a unit test project that includes the following folders:
29+
30+
- A folder that contains strongly typed classes for each mockable operation in your workflow.
31+
32+
- A folder for each unit test definition. This folder includes a C# file that contains a sample class and methods. You use this class and methods to set up your own assertions, confirm that the workflow behaves as expected, and make sure that the workflow behaves reliably and predictably in your larger Azure ecosystem.
3033

3134
## Prerequisites
3235

33-
- An Azure account and subscription. If you don't have a subscription, [sign up for a free Azure account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
34-
- A Standard logic app project in Visual Studio Code that contains a previously and locally executed workflow to use as the source for your unit test. For more information about Visual Studio Code setup and project creation, see [Create Standard logic app workflows with Visual Studio Code](https://learn.microsoft.com/azure/logic-apps/create-standard-workflows-visual-studio-code).
36+
- An Azure account and subscription. If you don't have a subscription, [sign up for a free Azure account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
37+
38+
- A Standard logic app project in Visual Studio Code that contains at least one workflow definition to use for creating a unit test.
39+
40+
For more information about Visual Studio Code setup and project creation, see [Create Standard logic app workflows with Visual Studio Code](/azure/logic-apps/create-standard-workflows-visual-studio-code).
3541

3642
## Limitations and known issues
3743

38-
- This release currently supports only C\# for creating unit tests.
39-
- This release doesn't support non-mocked actions. Make sure that all actions in the workflow execution path are mocked.
40-
- This release doesn't support the following action types:
41-
- Integration account
42-
- Data Mapper
43-
- Custom code
44-
- XML actions
45-
- Liquid actions
46-
- EDI encode and decode
44+
- This release currently supports only C# for creating unit tests.
45+
46+
- This release doesn't support non-mocked actions. Make sure that all actions in the workflow execution path are mocked.
47+
48+
- This release doesn't support the following action types:
49+
50+
- Integration account actions
51+
- Data Mapper actions
52+
- Custom code actions
53+
- XML actions
54+
- Liquid actions
55+
- EDI encode and decode actions
4756

4857
## Review the basic concepts
4958

5059
The following list includes basic but important concepts about unit tests for Standard workflows:
5160

52-
- **Logic app unit test**
61+
- **Logic app unit test**
5362

54-
A controlled workflow execution that injects mock objects. These objects represent either the workflow trigger or actions that depend on external services or systems.
63+
A controlled workflow execution that injects mock objects. These objects represent either the workflow trigger or actions that depend on external services or systems.
5564

56-
- **Mockable action**
65+
- **Mockable action**
5766

58-
A workflow action that depends on an external service or system. You can convert these actions to mocked actions for unit test creation and execution.
67+
A workflow action that depends on an external service or system. You can convert these actions to mocked actions for unit test creation and execution.
5968

6069
## Create a unit test from a workflow definition
6170

62-
1. In Visual Studio Code, open your Standard logic app project.
63-
2. In your project, expand the workflow definition folder.
64-
3. From the shortcut menu for **workflow.json** file, select **Open Designer**.
65-
4. On the designer toolbar, select **Create unit test**.
66-
67-
:::image type="content" source="media/create-unit-tests-standard-workflow-definitions-visual-studio-code/designer-vscode.png" alt-text="Screenshot shows Visual Studio Code with Standard logic app project, designer running, opened workflow design view, and selected command to create unit test." lightbox="media/create-unit-tests-standard-workflow-definitions-visual-studio-code/designer-vscode.png":::
68-
69-
6. Provide a name to use for the unit test, unit test class, and C\# file.
70-
71+
1. In Visual Studio Code, open your Standard logic app project.
72+
73+
1. In your project, expand the workflow definition folder.
74+
75+
1. From the shortcut menu for the **workflow.json** file, select **Open Designer**.
76+
77+
1. On the designer toolbar, select **Create unit test**.
78+
79+
:::image type="content" source="media/create-unit-tests-standard-workflow-definitions-visual-studio-code/designer.png" alt-text="Screenshot shows Visual Studio Code, Standard logic app project, workflow designer, and selected command to create unit test." lightbox="media/create-unit-tests-standard-workflow-definitions-visual-studio-code/designer.png":::
80+
81+
1. Provide a name to use for the unit test, unit test class, and C# file.
82+
7183
A new folder named **Tests** now appears in your project workspace. This folder has the following structure:
7284

73-
:::image type="content" source="media/create-unit-tests-standard-workflow-definitions-visual-studio-code/project-structure.png" alt-text="Screenshot shows Visual Studio Code, Standard logic app project, and Tests folder with unit test folders and files." lightbox="media/create-unit-tests-standard-workflow-definitions-visual-studio-code/project-structure.png":::
85+
:::image type="content" source="media/create-unit-tests-standard-workflow-definitions-visual-studio-code/unit-test-project-structure.png" alt-text="Screenshot shows Visual Studio Code, Standard logic app project, and Tests folder with unit test folders and files." lightbox="media/create-unit-tests-standard-workflow-definitions-visual-studio-code/unit-test-project-structure.png":::
7486

75-
| **Folder or file** |**Description** |
76-
|--------------------|----------------|
77-
| **`Tests`** <br>**\|\| <`logic-app-name`>** | In the **`Tests`** folder, a **<`logic-app-name`>** folder appears when you add unit tests to a logic app project.|
87+
| Folder or file | Description |
88+
|----------------|-------------|
89+
| **`Tests`** <br>**\|\| <`logic-app-name`>** | In the **`Tests`** folder, a **<`logic-app-name`>** folder appears when you add unit tests to a logic app project. |
7890
| **`Tests`** <br>**\|\| <`logic-app-name`>** <br>**\|\|\| <`workflow-name`>** | In the **<`logic-app-name`>** folder, a **<`workflow-name`>** folder appears when you add unit tests for a workflow. |
7991
| **`Tests`** <br>**\|\| <`logic-app-name`>** <br>**\|\|\| <`workflow-name`>** <br>**\|\|\|\| `MockOutputs`** <br>**\|\|\|\|\| <`operation-name-outputs`>**.**`cs`** | In the **<`workflow-name`>** folder, the **`MockOutputs`** folder contains a C# (**.cs**) file with strongly-typed classes for each connector operation in the workflow. Each **.cs** file name uses the following format: <br><br>**<`operation-name`>[`Trigger\|Action`]`Output.cs`** <br><br>If a connector operation has *dynamic contracts*, a class appears for each *dynamic type*. A dynamic type refers to an operation parameter that has different inputs and outputs based on the value provided for that parameter. You can use these classes to extend your unit tests and create new mocks from scratch. |
80-
| **`Tests`** <br>**\|\| <`logic-app-name`>** <br>**\|\|\| <`workflow-name`>** <br>**\|\|\|\| <`unit-test-name`>** <br>**\|\|\|\|\| <`unit-test-name`>`.cs`** | In the **<`workflow-name`>** folder, the **<`unit-test-name`>** folder contains the following files: <br><br>- The **<`unit-test-name`>`.cs`** file contains a sample C# class and methods used to run and assert results. You can edit this file to match your specific test scenarios. |
92+
| **`Tests`** <br>**\|\| <`logic-app-name`>** <br>**\|\|\| <`workflow-name`>** <br>**\|\|\|\| <`unit-test-name`>** <br>**\|\|\|\|\| <`unit-test-name`>`.cs`** | In the **<`workflow-name`>** folder, the **<`unit-test-name`>** folder contains a **<`unit-test-name`>`.cs`** file. You use this file, which contains a sample C# class and methods, to run and assert results. You can edit this file to match your specific test scenarios. |
8193

82-
## Review the \<unit-test-name\>.cs file
94+
## Review the unit test *.cs file
8395

8496
This unit test class provides a framework for testing Standard logic app workflows by mocking triggers and actions. This class lets you test workflows without actually calling external services or APIs.
8597

@@ -107,7 +119,7 @@ public class <unit-test-name>
107119

108120
#### Setup() method
109121

110-
This method instantiates the \`**TestExecutor\`** class by using the path to your test settings configuration file. The method runs before each test execution and creates a new instance of \`**TestExecutor\`**.
122+
This method instantiates the **`TestExecutor`** class by using the path to your test settings configuration file. The method runs before each test execution and creates a new instance of **`TestExecutor`**.
111123

112124
```csharp
113125
[TestInitialize]
@@ -125,23 +137,23 @@ The following section describes sample test methods that you can use in your uni
125137

126138
The following method shows how to use static mock data to test your workflow. In this method, you can complete the following tasks:
127139

128-
- Set property values on your mocked actions.
129-
- Execute the workflow with the configured mock data.
130-
- Confirm that the execution succeeded.
140+
- Set property values on your mocked actions.
141+
- Execute the workflow with the configured mock data.
142+
- Confirm that the execution succeeded.
131143

132144
```csharp
133145
[TestMethod]
134146
public async Task <workflow-name>_<unit-test-name>_ExecuteWorkflow_SUCCESS_Sample1()
135147
{
136148
// PREPARE mock: Generate mock trigger data.
137149
var triggerMockOutput = new WhenMessagesAreAvailableInAQueuePeeklockTriggerOutput();
138-
// Sample of how to set the properties of the triggerMockOutput
150+
// Sample that shows how to set the properties for triggerMockOutput
139151
// triggerMockOutput.Body.Id = "SampleId";
140152
var triggerMock = new WhenMessagesAreAvailableInAQueuePeeklockTriggerMock(outputs: triggerMockOutput);
141153

142154
// Generate mock action data.
143155
var actionMockOutput = new CallExternalAPIActionOutput();
144-
// Sample of how to set the properties of the actionMockOutput
156+
// Sample that shows how to set the properties for actionMockOutput
145157
// actionMockOutput.Body.Name = "SampleResource";
146158
// actionMockOutput.Body.Id = "SampleId";
147159
var actionMock = new CallExternalAPIActionMock(name: "Call_External_API", outputs: actionMockOutput);
@@ -168,8 +180,8 @@ public async Task <workflow-name>_<unit-test-name>_ExecuteWorkflow_SUCCESS_Sampl
168180

169181
The following method shows how to use dynamic mock data with callback methods. This approach gives you two options that dynamically generate mock data:
170182

171-
- Define a separate callback method.
172-
- Use an [inline lambda function](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-expressions)..
183+
- Define a separate callback method.
184+
- Use an [inline lambda function](/dotnet/csharp/language-reference/operators/lambda-expressions).
173185

174186
Both approaches let you create dynamic responses based on unit test execution context.
175187

@@ -225,19 +237,19 @@ The following section describes methods used by the sample test methods. Helper
225237

226238
#### Callback method
227239

228-
The following method dynamically generates mock data. You can edit this method to return different mock responses based on your test scenario requirements or use it as a template to create your own dynamic callback methods.
240+
The following method dynamically generates mock data. The method name varies based on the mocked action name in the test methods for static or dynamic mock data. You can edit this method to return different mock responses based on your test scenario requirements or use it as a template to create your own dynamic callback methods.
229241

230242
```csharp
231243
public CallExternalAPIActionMock CallExternalAPIActionMockOutputCallback(TestExecutionContext context)
232244
{
233-
// Sample mock data: Modify Dynamically change the mocked data dynamically for "actionName".
245+
// Sample mock data: Dynamically change the mocked data for 'actionName'.
234246
return new CallExternalAPIActionMock(
235247
status: TestWorkflowStatus.Succeeded,
236248
outputs: new CallExternalAPIActionOutput {
237249

238250
// If this account contains a JObject Body,
239251
// set the properties you want here:
240-
// Body = "something".ToJObject()
252+
// Body = "something".ToJObject()
241253
242254
}
243255
);
@@ -246,4 +258,4 @@ public CallExternalAPIActionMock CallExternalAPIActionMockOutputCallback(TestExe
246258

247259
## Related content
248260

249-
Create unit tests from a Standard workflow run in Azure Logic Apps with Visual Studio Code (Preview)
261+
[Create unit tests from Standard workflow runs in Azure Logic Apps with Visual Studio Code](/azure/logic-apps/create-unit-tests-standard-workflow-runs-visual-studio-codes)
46 KB
Loading
Loading

0 commit comments

Comments
 (0)