DEV Community

Kenichiro Nakamura
Kenichiro Nakamura

Posted on

Integration Test with Postman in Azure DevOps Pipeline: Part 3

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

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

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

image

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

2. Select Azure Resource Manager.

image

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

image

4. Select appropriate Azure Subscription and Resource Group, then give any name and save it.

image

Add Pipeline

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

1. Go to Pipelines and click Create Pipeline.

image

2. Select Azure Repos Git.

image

3. Select the repo.

image

4. Select ASP.NET Core template.

image

5. Once yaml is displayed, add dotnet publish task.

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: 'publish'
    publishWebProjects: true
Enter fullscreen mode Exit fullscreen mode

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

image

7. Select App Service to deploy and Add. If you use different service, edit yaml as you need.

image

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

- 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
Enter fullscreen mode Exit fullscreen mode

9. Save and run the pipeline. Confirm that newman section runs as expected.

image

Publish Test Report

newman support generating junit test report. See newman reporters for detail.

1. Update newman run task as below.

- 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
Enter fullscreen mode Exit fullscreen mode

2. Add test report publish task.

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: '**/*.xml'
    mergeTestResults: true
    failTaskOnFailedTests: true
  displayName: 'Publish Test Results'
Enter fullscreen mode Exit fullscreen mode

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

image

Summary

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

Top comments (0)