Skip to content

Commit a51cd11

Browse files
committed
PR Feedback
1 parent acef408 commit a51cd11

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

articles/azure-functions/durable/durable-functions-unit-testing-python.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.date: 05/07/2025
77
ms.author: azfuncdf
88
---
99

10-
# Unit Testing Durable Functions in Python
10+
# Unit testing Durable Functions in Python
1111

1212
Unit testing is an important part of modern software development practices. Unit tests verify business logic behavior and protect from introducing unnoticed breaking changes in the future. Durable Functions can easily grow in complexity so introducing unit tests helps avoid breaking changes. The following sections explain how to unit test the three function types - Orchestration client, orchestrator, and entity functions.
1313

@@ -23,7 +23,7 @@ The examples in this article require knowledge of the following concepts and fra
2323
* Python [unittest](https://docs.python.org/3/library/unittest.html)
2424
* [unittest.mock](https://docs.python.org/3/library/unittest.mock.html)
2525

26-
## Setting Up the Test Environment
26+
## Setting up the test environment
2727

2828
To test Durable Functions, it's crucial to set up a proper test environment. This includes creating a test directory and installing Python's `unittest` module into your Python environment. For more info, see the [Azure Functions Python unit testing overview](../functions-reference-python.md#unit-testing).
2929

articles/azure-functions/durable/durable-functions-unit-testing.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ The examples in this article require knowledge of the following concepts and fra
2828

2929
Mocking is supported via the following interface:
3030

31-
* [IDurableOrchestrationClient](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableorchestrationclient), [IDurableEntityClient](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableentityclient) and [IDurableClient](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableclient)
31+
* [IDurableOrchestrationClient](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableorchestrationclient), [IDurableEntityClient](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableentityclient), and [IDurableClient](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableclient)
3232

3333
* [IDurableOrchestrationContext](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableorchestrationcontext)
3434

3535
* [IDurableActivityContext](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableactivitycontext)
3636

3737
* [IDurableEntityContext](/dotnet/api/microsoft.azure.webjobs.extensions.durabletask.idurableentitycontext)
3838

39-
These interfaces can be used with the various trigger and bindings supported by Durable Functions. When executing your Azure Functions, the functions runtime will run your function code with a concrete implementation of these interfaces. For unit testing, you can pass in a mocked version of these interfaces to test your business logic.
39+
These interfaces can be used with the various trigger and bindings supported by Durable Functions. While it is executing your Azure Functions, the functions runtime runs your function code with a concrete implementation of these interfaces. For unit testing, you can pass in a mocked version of these interfaces to test your business logic.
4040

4141
## Unit testing trigger functions
4242

43-
In this section, the unit test will validate the logic of the following HTTP trigger function for starting new orchestrations.
43+
In this section, the unit test validates the logic of the following HTTP trigger function for starting new orchestrations.
4444

4545
[!code-csharp[Main](~/samples-durable-functions/samples/precompiled/HttpStart.cs)]
4646

47-
The unit test task will be to verify the value of the `Retry-After` header provided in the response payload. So the unit test will mock some of `IDurableClient` methods to ensure predictable behavior.
47+
The unit test task verifies the value of the `Retry-After` header provided in the response payload. So the unit test mocks some of `IDurableClient` methods to ensure predictable behavior.
4848

4949
First, we use a mocking framework ([moq](https://github.com/moq/moq4) in this case) to mock `IDurableClient`:
5050

@@ -54,7 +54,7 @@ var durableClientMock = new Mock<IDurableClient>();
5454
```
5555

5656
> [!NOTE]
57-
> While you can mock interfaces by directly implementing the interface as a class, mocking frameworks simplify the process in various ways. For instance, if a new method is added to the interface across minor releases, moq will not require any code changes unlike concrete implementations.
57+
> While you can mock interfaces by directly implementing the interface as a class, mocking frameworks simplify the process in various ways. For instance, if a new method is added to the interface across minor releases, moq doesn't require any code changes unlike concrete implementations.
5858
5959
Then `StartNewAsync` method is mocked to return a well-known instance ID.
6060

@@ -117,39 +117,39 @@ Assert.NotNull(result.Headers.RetryAfter);
117117
Assert.Equal(TimeSpan.FromSeconds(10), result.Headers.RetryAfter.Delta);
118118
```
119119

120-
After combining all steps, the unit test will have the following code:
120+
After you combine all these steps, the unit test has the following code:
121121

122122
[!code-csharp[Main](~/samples-durable-functions/samples/VSSample.Tests/HttpStartTests.cs)]
123123

124124
## Unit testing orchestrator functions
125125

126126
Orchestrator functions are even more interesting for unit testing since they usually have a lot more business logic.
127127

128-
In this section the unit tests will validate the output of the `E1_HelloSequence` Orchestrator function:
128+
In this section, the unit tests validate the output of the `E1_HelloSequence` Orchestrator function:
129129

130130
[!code-csharp[Main](~/samples-durable-functions/samples/precompiled/HelloSequence.cs)]
131131

132-
The unit test code will start with creating a mock:
132+
The unit test code starts with creating a mock:
133133

134134
```csharp
135135
var durableOrchestrationContextMock = new Mock<IDurableOrchestrationContext>();
136136
```
137137

138-
Then the activity method calls will be mocked:
138+
Then the activity method calls are mocked:
139139

140140
```csharp
141141
durableOrchestrationContextMock.Setup(x => x.CallActivityAsync<string>("E1_SayHello", "Tokyo")).ReturnsAsync("Hello Tokyo!");
142142
durableOrchestrationContextMock.Setup(x => x.CallActivityAsync<string>("E1_SayHello", "Seattle")).ReturnsAsync("Hello Seattle!");
143143
durableOrchestrationContextMock.Setup(x => x.CallActivityAsync<string>("E1_SayHello", "London")).ReturnsAsync("Hello London!");
144144
```
145145

146-
Next the unit test will call `HelloSequence.Run` method:
146+
Next, the unit test calls the `HelloSequence.Run` method:
147147

148148
```csharp
149149
var result = await HelloSequence.Run(durableOrchestrationContextMock.Object);
150150
```
151151

152-
And finally the output will be validated:
152+
And finally the output is validated:
153153

154154
```csharp
155155
Assert.Equal(3, result.Count);
@@ -158,19 +158,19 @@ Assert.Equal("Hello Seattle!", result[1]);
158158
Assert.Equal("Hello London!", result[2]);
159159
```
160160

161-
After combining all steps, the unit test will have the following code:
161+
After you combine the previous steps, the unit test has the following code:
162162

163163
[!code-csharp[Main](~/samples-durable-functions/samples/VSSample.Tests/HelloSequenceOrchestratorTests.cs)]
164164

165165
## Unit testing activity functions
166166

167-
Activity functions can be unit tested in the same way as non-durable functions.
167+
Activity functions are unit tested in the same way as nondurable functions.
168168

169-
In this section the unit test will validate the behavior of the `E1_SayHello` Activity function:
169+
In this section the unit test validates the behavior of the `E1_SayHello` Activity function:
170170

171171
[!code-csharp[Main](~/samples-durable-functions/samples/precompiled/HelloSequence.cs)]
172172

173-
And the unit tests will verify the format of the output. The unit tests can use the parameter types directly or mock `IDurableActivityContext` class:
173+
And the unit tests verify the format of the output. These unit tests either use the parameter types directly or mock `IDurableActivityContext` class:
174174

175175
[!code-csharp[Main](~/samples-durable-functions/samples/VSSample.Tests/HelloSequenceActivityTests.cs)]
176176

0 commit comments

Comments
 (0)