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: README.md
+46-3Lines changed: 46 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,17 @@
1
1
# Walkthrough: Automating REST API tests using Postman and Azure DevOps
2
2
## Overview
3
-
This walkthrough will take you through creating and automating some REST API tests using Postman and Azure DevOps. For this walkthrough, we'll be making use of HSBC's excellent (and public) branch locator API, which you can find here: https://api.hsbc.com/branch-locator.html. We assume you are comfortable creating basic API calls with Postman.
3
+
This walkthrough will take you through creating and automating some REST API tests using Postman and Azure DevOps. For this walkthrough, we'll be making use of HSBC's excellent (and public) branch locator API, which you can find here: https://api.hsbc.com/branch-locator.html.
4
+
5
+
We assume you are comfortable creating basic API calls with Postman.
4
6
5
7
We're going to do the following:
6
8
1. Create some API calls
7
9
2. Write some tests against them
8
10
3. Create an Azure DevOps Release pipeline to automate these tests
11
+
4. Run our pipeline!
9
12
## Prerequisites
10
13
* You must have installed the latest version of Postman App (https://www.postman.com/downloads/)
11
14
* You must have created a free account with Azure DevOps Services (https://azure.microsoft.com/en-gb/services/devops/)
12
-
* You must be
13
15
* You must be able to access the API above
14
16
## Creating the API calls
15
17
(If you don't want to create your own API calls, we've saved our own collection [here](https://github.com/bendalby82/azure-devops-rest-api/blob/master/postman/HSBC.postman_collection.json), which you can just import into Postman)
@@ -22,8 +24,49 @@ We're going to do the following:
22
24

23
25
24
26
## Write some tests against them
25
-
1. Postman has excellent documentation on how to write tests [here](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/02-Basic-Requests-Are-All-Green.png) - but we want a nice mixture of performance tests, status tests and data tests. Note the use of the requestName property, which will make our tests easier to read further down the line:
27
+
(Again, you can skip doing any work here by just importing our [completed collection](https://github.com/bendalby82/azure-devops-rest-api/blob/master/postman/HSBC.postman_collection.json))
28
+
1. Postman has excellent documentation on how to write tests [here](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/02-Basic-Requests-Are-All-Green.png) - but we want a nice mixture of performance tests, status tests and data tests. Note the use of the `pm.info.requestName` property, which will make our tests easier to read further down the line:
2. Make sure all of our requests have at least some tests against them:
29
32

33
+
34
+
## Create an Azure DevOps Release pipeline to automate these tests
35
+
We're going to automate our tests using a 'classic' release pipeline. In theory, Microsoft now support YAML pipelines for CD (see [announcement here](https://devblogs.microsoft.com/devops/announcing-general-availability-of-azure-pipelines-yaml-cd/)), but at time of writing this was all very new, and it was not obvious at all how to use these features.
36
+
1. Once we've logged into Azure DevOps Services, our first step is to create a new release pipeline under Pipelines > Releases:
37
+

38
+
39
+
2. Next step is to link the artifact containing your Postman collection and the npm package configuration you'll need to automate that. You're welcome to link to this repository, as shown below, although for some reason Azure wanted me to authenticate, even though the repo was public. Make sure you change the name of the artifact alias to `_Azure-DevOps-REST-API`:
40
+

41
+
42
+
3. Create a new Stage called 'live', and take advantage of Microsoft's shared agent as shown:
4. Add a new task of type 'npm', and configure as shown below (you can inspect our YAML [here](https://github.com/bendalby82/azure-devops-rest-api/blob/master/azure/YAML-01-NPM-Step.yaml)):
46
+

47
+
48
+
5. Add a new task of type 'Command line', and configure as shown below (again, our YAML is [here](https://github.com/bendalby82/azure-devops-rest-api/blob/master/azure/YAML-02-Command-Step.yaml)):
6. Add a new task of type 'Publish Test Results', and configure as shown below (our YAML is [here](https://github.com/bendalby82/azure-devops-rest-api/blob/master/azure/YAML-03-Publish-Test-Results-Step.yaml)):
52
+

53
+
54
+
7. Time to save all our work, before testing out our pipeline!
55
+
56
+
## Running the pipeline
57
+
58
+
1. Create a new release from your pipeline in the usual way:
0 commit comments