3
votes

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?

2

2 Answers

5
votes

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.

enter image description here

Then I specify the Path to publish field to folder that contains all the test files.

enter image description here

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.

enter image description here

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.

enter image description here

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.

enter image description here

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.

1
votes

I suppose you are using C# unit tests.

  1. Add new stage "Integration tests" right before stage "Deployment to Staging".

  2. Add task installing VSTest Platform. It will be cached in agent folder.

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/vstest-platform-tool-installer?view=azure-devops

  1. 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".

  2. Add VSTest task specyfing:

a) Test files -> for example "***IntegrationTests.dll"

b) Test platform version -> "Installed by Tools Installer"

https://docs.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.