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/azure-functions/durable/durable-functions-unit-testing-python.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ ms.author: azfuncdf
9
9
10
10
# Unit Testing Durable Functions in Python
11
11
12
-
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 will help to avoid breaking changes. The following sections explain how to unit test the three function types - Orchestration client, orchestrator, and entity functions.
12
+
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.
13
13
14
14
> [!NOTE]
15
15
> This guide applies only to Durable Functions apps written in the [Python v2 programming model](../functions-reference-python.md).
@@ -25,15 +25,15 @@ The examples in this article require knowledge of the following concepts and fra
25
25
26
26
## Setting Up the Test Environment
27
27
28
-
To test Durable Functions, it's crucial to set up a proper test environment. This includes creating a test directory and installing unittest into your Python environment. For more info, see the [Azure Functions Python unit testing overview](../functions-reference-python.md#unit-testing).
28
+
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).
29
29
30
30
## Unit testing trigger functions
31
31
32
32
Trigger functions, often referred to as _client_ functions, initiate orchestrations and external events. To test these functions:
33
33
34
34
- Mock the `DurableOrchestrationClient` to simulate orchestration execution and status management.
35
35
- Assign `DurableOrchestrationClient` methods such as `start_new`, `get_status`, or `raise_event` with mock functions that return expected values.
36
-
- Invoke the client function directly with a mocked client as well as other necessary inputs such as a `req` (HTTP request object) for HTTP trigger client functions.
36
+
- Invoke the client function directly with a mocked client and other necessary inputs such as a `req` (HTTP request object) for HTTP trigger client functions.
37
37
- Use assertions and `unittest.mock` tools to verify expected orchestration start behavior, parameters, and HTTP responses.
38
38
39
39
```python
@@ -71,9 +71,9 @@ class TestFunction(unittest.TestCase):
71
71
Orchestrator functions manage the execution of multiple activity functions. To test an orchestrator:
72
72
73
73
- Mock the `DurableOrchestrationContext` to control function execution.
74
-
- Replace `DurableOrchestrationContext` methods needed for orchestrator execution like `call_activity` or `create_timer` with mock functions. These functions should have pre-determined behavior and should typically return Task objects with a `result` property.
75
-
- Call the orchestrator recursively, passing the result of the Task generated by the previous yield statement to the next.
76
-
-Use the results returned from the orchestrator, as well as `unittest.mock` methods to verify the orchestrator result.
74
+
- Replace `DurableOrchestrationContext` methods needed for orchestrator execution like `call_activity` or `create_timer` with mock functions. These functions will typically return objects of type TaskBase with a `result` property.
75
+
- Call the orchestrator recursively, passing the result of the Task generated by the previous yield statement to the next.
76
+
-Verify the orchestrator result using the results returned from the orchestrator and `unittest.mock`.
77
77
78
78
```python
79
79
import unittest
@@ -90,6 +90,8 @@ class TestFunction(unittest.TestCase):
90
90
# Get the original method definition as seen in the function_app.py file
Copy file name to clipboardExpand all lines: articles/azure-functions/durable/durable-functions-unit-testing.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ ms.date: 11/03/2019
7
7
8
8
# Durable Functions unit testing (C#)
9
9
10
-
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 will help to avoid breaking changes. The following sections explain how to unit test the three function types - Orchestration client, orchestrator, and activity functions.
10
+
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 activity functions.
11
11
12
12
> [!NOTE]
13
13
> This article provides guidance for unit testing for Durable Functions apps written in C# for the .NET in-process worker and targeting Durable Functions 2.x. For more information about the differences between versions, see the [Durable Functions versions](durable-functions-versions.md) article.
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-reference-python.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1427,6 +1427,9 @@ class TestFunction(unittest.TestCase):
1427
1427
1428
1428
Inside your *.venv* Python virtual environment folder, install your favorite Python test framework, such as `pip install pytest`. Then run `pytest tests` to check the test result.
1429
1429
1430
+
> [!NOTE]
1431
+
> Durable Functions require special syntax for unit testing. For more information, refer to [Unit Testing Durable Functions in Python](durable-functions-unit-testing-python.md)
0 commit comments