Integration Test with Postman in Azure DevOps Pipeline: Part 3
Tags: azure, postman, devops, pipeline
Published: 2021-04-25 17:32:42

In this article, I use Azure DevOps pipeline to run the postman collection.

# Azure Web Apps

We need a place to host our app. I created Azure Web Apps for .NET 5. You can select any place to host the application.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p8zwv3y46orqwstn97v1.png)

# Azure DevOps Repo

I created new Azure DevOps project and commit all code. If you already have your own repo, then please use it.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xgucof2p4em0xwqnpi7.png)

Make sure that mywebapi.postman_environment.json has correct address value.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fuamnuf96wfemyf7t60l.png)
 
# Service Connection

To deploy the web app, create **Service Connection** in Azure DevOps.

1\. Select **Project settings** and click **Service Connections**. Then click *Create service connection** button.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eeyy9ikrprv4tn4yuhps.png)

2\. Select Azure Resource Manager.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zhsycmuhklmnxjlnulrt.png)

3\. Select authentication method. I use recommended method here.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6v3xb4bxm58u7xf0218.png)

4\. Select appropriate Azure Subscription and Resource Group, then give any name and save it.
 
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ao37fdtzafrx6prf5b0.png)
 
# Add Pipeline

Let's add new pipeline to run the postman collection.

1\. Go to Pipelines and click **Create Pipeline**.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d5b0rqe4m64l2f5si8h7.png)
 
2\. Select **Azure Repos Git**.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dheyfipl0s7ngmasuz8r.png)

3\. Select the repo.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z8rmgo2anktjp2d4qqyp.png)
 
4\. Select **ASP.NET Core** template.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dpcwtr1azbmwn4sqgf1b.png)
 
5\. Once yaml is displayed, add dotnet publish task.

```yaml
- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: 'publish'
    publishWebProjects: true
```

6\. Then, select **Azure App Service deploy** from Tasks helper.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v9afby0l9yuwwa4yr38v.png)
 
7\. Select App Service to deploy and Add. If you use different service, edit yaml as you need.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hh3ulzodtsijcoxkqs92.png) 

8\. Add bash task to install and run the newman.

```yaml
- task: Bash@3
  displayName: 'run newman'
  inputs:
    targetType: 'inline'
    script: |
      npm install -g newman
      newman run $(Build.SourcesDirectory)/postman_collection/mywebapi.postman_collection.json -e $(Build.SourcesDirectory)/postman_collection/mywebapi.postman_environment.json
```
 
9\. Save and run the pipeline. Confirm that newman section runs as expected.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z16idyt1xwx8urzlz6d1.png)

# Publish Test Report

newman support generating junit test report. See [newman reporters](https://www.npmjs.com/package/newman#reporters) for detail.

1\. Update newman run task as below. 

```yaml
- task: Bash@3
  displayName: 'run newman'
  inputs:
    targetType: 'inline'
    script: |
      npm install -g newman
      newman run $(Build.SourcesDirectory)/postman_collection/mywebapi.postman_collection.json -e $(Build.SourcesDirectory)/postman_collection/mywebapi.postman_environment.json --reporters cli,junit --reporter-junit-export junit-report.xml
```

2\. Add test report publish task.

```yaml
- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: '**/*.xml'
    mergeTestResults: true
    failTaskOnFailedTests: true
  displayName: 'Publish Test Results'
```

3\. Save and run the pipeline. Once the pipeline completed, check **Tests** tab of the pipeline result. The report should be published.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cszt9qaz40ksextv7w2z.png)
 
# Summary

In this article, I use Azure DevOps to run postman collection and publish the test report. Hope you find these series useful :)