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.
Azure DevOps Repo
I created new Azure DevOps project and commit all code. If you already have your own repo, then please use it.
Make sure that mywebapi.postman_environment.json has correct address value.
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.
2. Select Azure Resource Manager.
3. Select authentication method. I use recommended method here.
4. Select appropriate Azure Subscription and Resource Group, then give any name and save it.
Add Pipeline
Let's add new pipeline to run the postman collection.
1. Go to Pipelines and click Create Pipeline.
2. Select Azure Repos Git.
3. Select the repo.
4. Select ASP.NET Core template.
5. Once yaml is displayed, add dotnet publish task.
- task: DotNetCoreCLI@2
displayName: 'dotnet publish'
inputs:
command: 'publish'
publishWebProjects: true
6. Then, select Azure App Service deploy from Tasks helper.
7. Select App Service to deploy and Add. If you use different service, edit yaml as you need.
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
9. Save and run the pipeline. Confirm that newman section runs as expected.
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
2. Add test report publish task.
- 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.
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)