You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/logic-apps/create-unit-tests-standard-workflow-definitions-visual-studio-code.md
+66-54Lines changed: 66 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,85 +1,97 @@
1
1
---
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.
4
4
services: logic-apps
5
5
ms.suite: integration
6
+
author: wsilveiranz
7
+
ms.author: wsilveira
6
8
ms.reviewer: estfan, azla
7
9
ms.topic: how-to
8
10
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.
9
12
---
10
13
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)
12
15
13
16
> [!NOTE]
14
17
>
15
18
> 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/).
16
19
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.
18
21
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 servicesor 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:
20
23
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.
23
25
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.
25
27
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.
30
33
31
34
## Prerequisites
32
35
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).
35
41
36
42
## Limitations and known issues
37
43
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
47
56
48
57
## Review the basic concepts
49
58
50
59
The following list includes basic but important concepts about unit tests for Standard workflows:
51
60
52
-
-**Logic app unit test**
61
+
-**Logic app unit test**
53
62
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.
55
64
56
-
-**Mockable action**
65
+
-**Mockable action**
57
66
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.
59
68
60
69
## Create a unit test from a workflow definition
61
70
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
+
71
83
A new folder named **Tests** now appears in your project workspace. This folder has the following structure:
72
84
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":::
74
86
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.|
78
90
|**`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. |
79
91
|**`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`** filecontains 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. |
81
93
82
-
## Review the \<unit-test-name\>.cs file
94
+
## Review the unittest*.cs file
83
95
84
96
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.
85
97
@@ -107,7 +119,7 @@ public class <unit-test-name>
107
119
108
120
#### Setup() method
109
121
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`**.
111
123
112
124
```csharp
113
125
[TestInitialize]
@@ -125,23 +137,23 @@ The following section describes sample test methods that you can use in your uni
125
137
126
138
The following method shows how to use static mock data to test your workflow. In this method, you can complete the following tasks:
127
139
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.
@@ -168,8 +180,8 @@ public async Task <workflow-name>_<unit-test-name>_ExecuteWorkflow_SUCCESS_Sampl
168
180
169
181
The following method shows how to use dynamic mock data with callback methods. This approach gives you two options that dynamically generate mock data:
170
182
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).
173
185
174
186
Both approaches let you create dynamic responses based on unit test execution context.
175
187
@@ -225,19 +237,19 @@ The following section describes methods used by the sample test methods. Helper
225
237
226
238
#### Callback method
227
239
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.
// Sample mock data: Modify Dynamically change the mocked data dynamically for "actionName".
245
+
// Sample mock data: Dynamically change the mocked data for 'actionName'.
234
246
returnnewCallExternalAPIActionMock(
235
247
status: TestWorkflowStatus.Succeeded,
236
248
outputs: newCallExternalAPIActionOutput {
237
249
238
250
// If this account contains a JObject Body,
239
251
// set the properties you want here:
240
-
// Body = "something".ToJObject()
252
+
// Body = "something".ToJObject()
241
253
242
254
}
243
255
);
@@ -246,4 +258,4 @@ public CallExternalAPIActionMock CallExternalAPIActionMockOutputCallback(TestExe
246
258
247
259
## Related content
248
260
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)
0 commit comments