Azure Devops: How to add automated integration test during release pipeline - azure-devops

I have a staged release pipeline that deploys to Development and then to Staging.
I want my Integration Test project to run during release pipeline only before deployment to staging. How do I do that? is there a specific test task that I will be able to hook into before the staging deployment? like a pre-deploy task or something?

In order to run Integration Tests in your release pipeline. You should include your Test projects or test assembly dll files in the artifacts published in your build pipeline. So that your Integration test projects are accessible to the test tasks in your release pipeline.
To Include your test files in the artifacts. You can add a second publish build artifacts task in your Build Pipeline. Specify Path to publish to the location of your test files. Fore below example.
I add a another publish build artifacts task to publish all the test files that needed to run the tests.
Then I specify the Path to publish field to folder that contains all the test files.
After the build pipeline completed. You will see the Test folder being added to the build artifacts and published to the azure devops pipeline server.
Now you can run your tests in your release pipeline by adding the VsTest task or other test tasks in your release pipeline. The release pipeline will download your artifacts to
folder $(System.DefaultWorkingDirectory)(eg. C:\agent_work\r1\a).
For above example you will find the test files in folder $(System.DefaultWorkingDirectory)\artifact_alias\Test and the artifacts to be deployed in $(System.DefaultWorkingDirectory)\artifact_alias\drop.
Then you can either create a new stage with vstest task before deployment stage as #Kontekst mentioned, or just add the vstest task on the top of your deployment stage before your deployment task.
In above screenshot I add the Vstest task before the Azure deployment task and point the Search folder to the Test folder where the test files reside.
Update:
You can find the artifacts-alias in the field shown in below screenshot.
The main idea is to publish the test files in the artifacts in build pipeline and then add the test tasks in the release pipeline to run the tests.

I suppose you are using C# unit tests.
Add new stage "Integration tests" right before stage "Deployment to Staging".
Add task installing VSTest Platform. It will be cached in agent folder.
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/vstest-platform-tool-installer?view=azure-devops
Add to your tests projects proper unit tests adapter NuGet package, so that VSTest Platform will be able to find unit tests in dll assemblies, for example for NUnit tests it will be "NUnit 3 Test Adapter".
Add VSTest task specyfing:
a) Test files -> for example "***IntegrationTests.dll"
b) Test platform version -> "Installed by Tools Installer"
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/test/vstest?view=azure-devops
All test results returned by VSTest task will be integrated with Azure DevOps services.

I Love both answers by Levi Lu-MSFT and Kontekst!
My team used to do it like that and it got the job done.
However if you'd like more "fancier" reporting and if like me, you were looking for something out of the box that Microsoft was offering specifically for integration tests or automated tests then Azure DevOps' Test Plan feature might be what you're looking for.
Test Plans really seem to be catering for actual web automated tests but you can basically run any tests that you can fit in a release pipeline.
It integrates well with Visual Studio Test Manager.
Here's the link to the documentation: https://learn.microsoft.com/en-us/azure/devops/test/run-automated-tests-from-test-hub?view=azure-devops
And here's some screenshots in case the link fails in the future:

Related

Azure pipeline build artifacts for previous builds

We have a .NET ASP Web form application. Currently we use TeamCity for the CI part. Deployment part is manual. We take the build artifact generated by TeamCity and deploy the artifact manually.
Now we will be using Azure DevOps for complete CICD process. During the POC we have been able to successfully build and deploy the application in IIS. I am new to the azure pipeline and doing POCs to learn it.
In TeamCity, against each build the generated build artifacts are available. So we can easily refer to any specific build and get the build artifact for that specific build. This is useful in case of rollback. We take the last successfully build artifacts and deploy the same in case of any error.
But in Azure is there any build artifacts repository where we can get the all the build artifacts for all the builds of that pipeline ? There is a section "Artifacts" but as per my knowledge this is for publishing as packages across feeds.
Now I have come across JFrog artifact repository https://jfrog.com/artifactory/. But no nothing about this. Need to go through.
Anyone can please let me know , in azure pipelines , where I can get all the build artifacts against all the builds in a pipeline. Is it available against each run in the pipeline or I need to configure it somehow ?
In any release failure , I need to rollback to the last successful deployed artifact version.
Thanks in advance for any guidance on this.
Azure Artifacts is feed source for packages like nuget etc.
And build/pipeline artifact you can find in your build here (of course if you published them):
Here you have documentation about publishing and downloading pipeline artifacts - newer and recommended approach and here about build artifacts
In short what you needs is add this step:
- task: PublishPipelineArtifact#0
displayName: 'Publish pipeline artifacts'
inputs:
targetPath: $(Build.ArtifactStagingDirectory)/
archiveFilePatterns: '**/*.zip'
Of course if your pipeline output is a nuegt package you can publish it to Azure Artifacts.

Run tests in parallel using the Visual Studio Test task is failing

We are trying to Run tests in parallel using the Visual Studio Test task based on below link but we noticed "Run Unit tests" step failing due to packages directory was not found. Trying to contact Azure DevOps team to get some help here.
https://learn.microsoft.com/en-us/azure/devops/pipelines/test/parallel-testing-vstest?view=azure-devops
We tried to publish the test files as artifacts from the first job. And download the test artifacts to the second job. But we found the test files were located separately and there were many test data files needed to be published too. It was hard to publish all the test files to azure devops sever. And the vstest task failed with either assemblies not found error or some testcases just failed.
We also tried configuring a single job running in parallel with both build tasks and vstest task. It turned out the publish build artifacts task didnot work properly in parallel jobs.
After many times try and working together with #NAGAJU. The workaround we found is to configure two agent jobs to separate the publish artifacts task and Vstest task.
The first agent job with build tasks and publish artifacts tasks runs in an single agent. The second job with build tasks and Vstest task to run the tests in multiple agents in parallel.

Set up Azure Pipeline for Test Automation Framework

I need assistance in running my test scripts built-in Java platform with selenium webdriver using Eclipse IDE for my repo and used git to push my repo to Azure DevOps. The project is set up in Maven. How do I run my test scripts using pipelines in Azure DevOps?
Not sure get more details from you. So here just share my suggestion on how to run Selenium tests in the release pipeline for Java application.
In my scenario, I deploy my Java application to azure web app service then run it. If you don't want, you can also deploy to local tomcat by using this extension.
1) After the Java application build, copy the project to the artifact of the release during Build pipeline via copy files and publish artifact task.
2) Create release pipeline, then add Azure app service task to deploy my Java application to azure.
3) Add a Maven task to the release pipeline, configure the task to make it point to pom.xml file which located in artifact.
4) Trigger the Selenium tests in pom.xml.
Now you can run browser to view the test.
You can check this lab blog to get more details. Just focus on the design logic of pipeline execution, because the sample in that blog is running with vstest.exe.

.NET Core WebJob Console App CI/CD using Azure DevOps Pipelines

I'm trying to build my console application through Azure DevOps. So to this I'm following this tutorial.
The follow images, are from what I already did.
Build Solution Pipeline
Build Solution Pipeline / Publish
Build Solution Pipeline / Artifact
Deploy WebJob Pipeline
Deploy WebJob Pipeline / Variables
When I run the Build Solution the zip seems to work, because I see it.
But when I run the Deploy WebJob Pipeline I get ##[error]D:\a\1\s\***.zip not found.. I tried wwwroot/App_Data/jobs/, but still the same error.
What could I be doing wrong? What's the right way to set the zippedArtifactPath?
You're following the tutorial incorrectly. The tutorial is telling you to create a release. You're using a build pipeline to try to release. Although you can do that, you shouldn't.
You have two options:
If you want to keep using the visual designer, use a release. Look at the "Release" tab for this. Releases can be tied to build artifacts and will handle downloading the build artifact automatically.
If you want to use YAML, refer to the YAML documentation and set up a multi-stage pipeline to release.
What could I be doing wrong?
Check your error messgae ##[error]D:\a\1\s\***.zip not found we can find in the second build pipeline, the PS tried to get the xx.zip in xxx\s folder while in first build pipeline you published the xx.zip to xxx\a folder.
The $(System.DefaultWorkingDirectory) for build pipeline is xx\s folder while that for release pipeline is xx\a folder. In first build pipeline we published the xx.zip to Build.ArtifactStagingDirectory which is a xx\a folder, so we can't access the xx.zip from xx\s folder in second build pipeline's PS script.
What's the right way to set the zippedArtifactPath?
It's not recommended to build and deploy one web app using two build pipelines. For normal logic, we should do this by using combination like build+release pipeline just like the Toturial and Daniel suggests above.
We can use this variable $(Release.PrimaryArtifactSourceAlias) to get the artifact directory.
In your powerShell script you can set path variable like:
$path = "$(System.DefaultWorkingDirectory)\$(Release.PrimaryArtifactSourceAlias)\webjobs_drop\[ZIP_File_Name].zip"
[your build artifact name]\webjobs_drop[your zipped files].zip
"your build artifact name" - you should get it from your release pipelines Artifacts stage from where you are selecting your build artifacts

Executing SpecFlow tests in VSTS Release phase using SpecRun

We've built a number of tests using SpecFlow and are using SpecRun to run the tests locally and on the build agent. Wed like to take the tests out of the build and stick them in the first release phase of the VSTS Release we have linked to the build.
The team followed the guidance from Tarun and Utkarsh to setup SpecRun in the build, but when we use the Publish Artefact task to package up all the test assemblies, they aren't found when running on the Release Agent.
When building the project on the build agent, the NuGet references of the solution are restored to the packages folder, this includes the SpecRun.Runner package which contains the Visual Studio Test Adapter to discover and run the tests.
This test runner package isn't copied to the output directory of the Test Project. The VsTest task in the build will automatically detect the test runner from the packages directory, which is why it works like magic in the build phase.
To make it work in Release we've found a few options:
ugly use the publish artefact option and publish the solution packages folder. In the release stage point the VsTest step to the other artefact location to find the Test Adapter:
better use the nuget to install the SpecRun.Runner nuget as part of the release stage. This runs the risk of the build downloading a newer or unexpected version of the SpecRun.Runner package.
best check in a separate packages.config with the reference to the SpecRun.Runner project and its dependencies, restore it during the build and attach it as a separate artefact to the build. This ensures the Release stages will be able to use the same version of the SpecRun.Runner and that the version is stored in source control.