This guide provides a step-by-step walkthrough for setting up automated tests in your CI/CD pipeline using the built-in VSTest@3 task in Azure DevOps.
VSTest@3 is an Azure DevOps Pipelines task that runs automated tests as part of your CI/CD workflow. It leverages Microsoft's VSTest.Console.exe to execute unit tests in Visual Studio projects.
In a CI/CD context, VSTest@3 provides:
- ✅ Automatic discovery of test DLLs (using wildcards such as
*Tests.dll) - ✅ Remote test execution on both hosted and self-hosted build agents
- ✅ Generation of detailed test reports in the
.trxformat that integrate with Azure DevOps reporting - ✅ Advanced configurations including:
- Parallel test execution
- Filtering or excluding specific tests
- Collecting code coverage data
- Diagnostic logging
The following table compares features between dotnet test (typically used in VS Code) and VSTest@3 (designed for Azure DevOps):
| Feature | dotnet test (VS Code) |
VSTest@3 (Azure DevOps) |
|---|---|---|
| ✅ Runs tests? | Yes | Yes |
| 🚫 Runs in CI/CD? | No (intended for local development) | Yes (specifically for pipelines) |
| ✅ Automatically finds tests? | Yes | No (requires specifying *Tests.dll) |
| 🚫 Generates test reports? | No (by default) | Yes (produces .trx reports for Azure DevOps) |
| Limited options | Yes (supports testFiltercriteria) |
|
| 🚫 Supports code coverage? | No (by default) | Yes (codeCoverageEnabled: true) |
| Limited | Yes |
A well-structured repository is essential for maintainability and testability. Below are some guidelines for organizing your projects.
In the root directory of your repository:
- Create a
deployments/folder to store all DevOps-related assets. - Inside
deployments/, create a folder for your Logic App (e.g.,MyLogicAppDeployment). - Within that folder, create a subfolder named
pipelines/. - Place your CI configuration YAML file (e.g.,
CI-Pipeline.yml) inside thepipelines/directory.
Example structure:
deployments/
└── MyLogicAppDeployment/
└── pipelines/
└── CI-Pipeline.yml
This structure promotes separation of concerns, simplifies CI configuration management, and scales well for multiple workflows or environments.
- Separate projects: Keep your Logic App project and Unit Test project in distinct directories.
├── MyLogicApp/ # Azure Logic App Standard project
│ ├── .vscode/
│ ├── Artifacts/
│ ├── lib/
│ ├── MyWorkflowSample/ # Workflow definitions folder
│ │ └── workflow.json # Workflow JSON (triggers, actions, etc.)
│ ├── workflow-designtime/
│ │ ├── host.json
│ │ └── local.settings.json
│ ├── .funcignore
│ ├── .gitignore
│ ├── connections.json
│ ├── host.json
│ ├── local.settings.json
│ └── parameters.json
├── Tests/ # Unit and integration test project
│ ├── MyLogicAppTestProject/ # Main test project folder
│ │ ├── bin/ # Compiled binary output (autogenerated)
│ │ ├── obj/ # Intermediate build files (autogenerated)
│ │ ├── MySampleWorkflow/ # Grouping tests for a specific workflow
│ │ │ └── MockOutputs/ # Contains mock data for test execution
│ │ │ └── MyWorkflowTest.cs # C# test class for workflow testing
│ ├── TestExecutor.cs # Shared utility for executing tests
│ ├── MyLogicAppTestProject.csproj # Project file for the test project
│ └── Tests.sln # Visual Studio solution file for tests
├── deployments/ # CI/CD deployment folder
│ ├── MyLogicAppDeployment/ # Deployment artifacts for the Logic App
│ │ ├── pipelines/ # CI/CD pipeline definitions
│ │ │ └── CI-Pipeline.yml # Pipeline configuration file
Note: Ensure that the unit test project references the main Logic App project to access workflow definitions and shared components.
Follow these steps to create your azure-pipelines.yml file:
Specify which branches will trigger the pipeline:
trigger:
branches:
include:
- main # Run pipeline on push to main branch
- devFeatureBranch # Run pipeline on push to feature branchesSelect a Microsoft-hosted agent with the latest Windows environment:
pool:
vmImage: 'windows-latest' # Latest Windows VM for build/testInstall the required .NET SDK to ensure the correct build environment:
steps:
- task: UseDotNet@2
displayName: 'Install .NET SDK'
inputs:
packageType: 'sdk'
version: '6.x' # Adjust to your project’s .NET versionRestore all project dependencies to ensure necessary packages are available:
- script: dotnet restore
displayName: 'Restore NuGet Packages'
workingDirectory: ./TestsCompile the solution in Release mode. The --no-restore flag is used since dependencies have been restored:
- script: dotnet build --configuration Release --no-restore
displayName: 'Build Solution'
workingDirectory: ./TestsConfigure the pipeline to run your unit tests:
- task: VSTest@3
displayName: 'Run Unit Tests'
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: '**/*Tests.dll' # Runs all test assemblies
searchFolder: '$(Build.SourcesDirectory)/LogicAppProject/tests' # Update as necessary
codeCoverageEnabled: true
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'Explanation:
- Test Selection: Uses a wildcard (
*Tests.dll) to discover test assemblies. - Search Folder: Specifies where test assemblies are located.
- Code Coverage: Enables code coverage reporting to provide insight into test coverage.
Finally, publish the test results so that they appear in the Azure DevOps pipeline summary:
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '**/TestResults/*.trx'
mergeTestResults: true