Skip to content

Commit e8db067

Browse files
authored
Update README.md
1 parent 2bd6911 commit e8db067

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# Walkthrough: Automating REST API tests using Postman and Azure DevOps
22
## 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.
46

57
We're going to do the following:
68
1. Create some API calls
79
2. Write some tests against them
810
3. Create an Azure DevOps Release pipeline to automate these tests
11+
4. Run our pipeline!
912
## Prerequisites
1013
* You must have installed the latest version of Postman App (https://www.postman.com/downloads/)
1114
* You must have created a free account with Azure DevOps Services (https://azure.microsoft.com/en-gb/services/devops/)
12-
* You must be
1315
* You must be able to access the API above
1416
## Creating the API calls
1517
(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:
2224
![Basic requests are green](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/02-Basic-Requests-Are-All-Green.png)
2325

2426
## 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:
2629
![JavaScript tests](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/03-Write-Some-Test-Cases-With-Data-Check.png)
2730

2831
2. Make sure all of our requests have at least some tests against them:
2932
![All requests have tests](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/04-Requests-Now-All-Have-Tests.png)
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+
![Create new pipeline](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/10-Create-New-Release-Pipeline.png)
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+
![Link to Ben repo](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/11-Add-GitHub-Artifact.png)
41+
42+
3. Create a new Stage called 'live', and take advantage of Microsoft's shared agent as shown:
43+
![Configure agent](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/12-Choose-Ubuntu-And-Azure-Pipelines.png)
44+
45+
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+
![Set up npm](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/13-Add-NPM-Command.png)
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)):
49+
![Calling newman](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/14-Add-Newman-Command.png)
50+
51+
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+
![Publish test results](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/15-Add-Publish-Test-Results-Command.png)
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:
59+
![Create release](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/20-Create-Release.png)
60+
61+
2. Check it is green once completed:
62+
![Green for live](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/21-Release-Is-Green.png)
63+
64+
3. Click on the stage and then 'Tests' to see a summary:
65+
![Stage summary](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/22-Looking-At-Run-Summary.png)
66+
67+
4. Clear the filters from the test case pane to see detailed results:
68+
![Detailed results](https://github.com/bendalby82/azure-devops-rest-api/blob/master/images/23-Looking-At-Detailed-Results.png)
69+
70+
## Credits
71+
This post builds on work by Alee, which was written up on Medium:
72+
https://medium.com/younited-tech-blog/integrate-automated-test-in-azure-devops-using-the-postman-api-288f5566bf11

0 commit comments

Comments
 (0)