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/api-management/developer-portal-testing.md
+15-22Lines changed: 15 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,10 @@ titleSuffix: Azure API Management
4
4
description: Learn how to set up unit tests and end-to-end tests for your self-hosted API Management portal.
5
5
author: dlepow
6
6
ms.author: danlep
7
-
ms.date: 03/25/2021
7
+
ms.date: 02/09/2026
8
8
ms.service: azure-api-management
9
9
ms.topic: how-to
10
+
#customer intent: As a developer who maintains a self-hosted API Management portal, I need to create unit tests and end-to-end tests to verify the API for ongoing changes.
10
11
---
11
12
12
13
# Test the self-hosted developer portal
@@ -15,21 +16,19 @@ ms.topic: how-to
15
16
16
17
This article explains how to set up unit tests and end-to-end tests for your [self-hosted portal](developer-portal-self-host.md).
17
18
18
-
## Unit tests
19
+
## Create unit tests
19
20
20
-
A unit test is an approach to validate small pieces of functionality. It's done in isolation from other parts of the application.
21
+
A unit test is an approach to validate small pieces of functionality. A unit test operates in isolation from other parts of the application.
21
22
22
23
### Example scenario
23
24
24
25
In this scenario, you're testing a password input control. It only accepts passwords containing at least:
25
26
26
27
- One letter
27
-
28
28
- One number
29
-
30
29
- One special character
31
30
32
-
So, the test to validate these requirements looks like this:
31
+
The test to validate these requirements looks like this:
It's common to keep a unit test next to the component it's supposed to validate.
48
+
It's common to keep a unit test next to the component that it validates.
50
49
51
50
```console
52
51
component.ts
@@ -68,9 +67,9 @@ httpClient.mock()
68
67
});
69
68
```
70
69
71
-
## End-to-end tests
70
+
## Create end-to-end tests
72
71
73
-
An end-to-end test executes a particular user scenario taking exact steps that you expect the user to carry out. In a web application like te Azure API Management developer portal, the user scrolls through the content and selects options to achieve certain results.
72
+
An end-to-end test runs a particular user scenario taking exact steps that you expect the user to carry out. In a web application like the Azure API Management developer portal, the user scrolls through the content and selects options to achieve certain results.
74
73
75
74
To replicate user navigation, you can use browser manipulation helper libraries like [Puppeteer](https://github.com/puppeteer/puppeteer). It lets you simulate user actions and automate assumed scenarios. Puppeteer also automatically takes screenshots of pages or components at any stage of the test. Compare them later with previous results to catch deviations and potential regressions.
76
75
@@ -79,15 +78,10 @@ To replicate user navigation, you can use browser manipulation helper libraries
79
78
In this scenario, you need to validate a user sign-in flow. This scenario would require the following steps:
80
79
81
80
1. Open browser and navigate to the sign-in page.
82
-
83
81
1. Enter the email address.
84
-
85
82
1. Enter the password.
86
-
87
83
1. Select **Sign-in**.
88
-
89
84
1. Verify that user got redirected to Home page.
90
-
91
85
1. Verify that the page includes the **Profile** menu item. It's one of the possible indicators that you successfully signed in.
92
86
93
87
To run the test automatically, create a script with exactly the same steps:
> Strings such as "#email", "#password" and "#signin" are CSS-like selectors that identify HTML elements on the page. See the [Selectors Level 3](https://www.w3.org/TR/selectors-3/) W3C specification to learn more.
112
+
> Strings such as `#email`, `#password`, and `#signin` are CSS-like selectors that identify HTML elements on the page. For more information, see [Selectors Level 3 W3C specification](https://www.w3.org/TR/selectors-3/).
119
113
120
114
### UI component maps
121
115
122
-
User flows often go through the same pages or components. A good example is the main website menu that is present on every page.
116
+
User flows often go through the same pages or components. A good example is the main website menu that's present on every page.
123
117
124
118
Create a UI component map to avoid configuring and updating the same selectors for every test. For example, you could replace steps 2 through 6 in the preceding example with just two lines:
Certain scenarios may require pre-created data or configuration. For example, you may need to automate user sign-in with social media accounts. It's hard to create that data quickly or easily.
127
+
Certain scenarios require pre-created data or configuration. For example, you might need to automate user sign-in with social media accounts. It's hard to create that data quickly or easily.
134
128
135
129
For this purpose, you could add a special configuration file to your test scenario. The test scripts can pick up required data from the file. Depending on the build and test pipeline, the tests can pull the secrets from a named secure store.
136
130
@@ -174,7 +168,7 @@ Here's an example of a `validate.config.json` that would be stored in the `src`
174
168
175
169
### Headless vs normal tests
176
170
177
-
Modern browsers such as Chrome or Microsoft Edge allows you to run automation in both headless mode and normal mode. The browser operates without a graphical user interface in headless mode. It still carries out the same page and Document Object Model (DOM) manipulations. The browser UI usually isn't needed in delivery pipelines. In that case, running tests in headless mode is a great option.
171
+
Modern browsers, such as Chrome or Microsoft Edge, allow you to run automation in both headless mode and normal mode. The browser operates without a graphical user interface in headless mode. It still carries out the same page and Document Object Model (DOM) manipulations. The browser UI usually isn't needed in delivery pipelines. In that case, running tests in headless mode is a great option.
178
172
179
173
When you develop a test script, it's useful to see what exactly is happening in the browser. That's a good time to use normal mode.
There are two built-in ways to execute tests in this project:
193
+
There are two built-in ways to run tests in this project:
200
194
201
195
**npm command**
202
196
@@ -206,7 +200,7 @@ npm run test
206
200
207
201
**Test Explorer**
208
202
209
-
The Test Explorer extension for VS Code (for example, [Mocha Test Explorer](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter)) has a convenient UI and an option to run tests automatically on every change of the source code:
203
+
Use a Test Explorer extension for VS Code. For example, [Mocha Test Explorer](https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter) has a convenient UI and an option to run tests automatically on every change of the source code:
210
204
211
205
:::image type="content" source="media/developer-portal-testing/visual-studio-code-test-explorer.png" alt-text="Screenshot of Visual Studio Code Test Explorer":::
212
206
@@ -215,5 +209,4 @@ The Test Explorer extension for VS Code (for example, [Mocha Test Explorer](http
215
209
Learn more about the developer portal:
216
210
217
211
-[Azure API Management developer portal overview](api-management-howto-developer-portal.md)
218
-
219
212
-[Self-host the developer portal](developer-portal-self-host.md)
0 commit comments