Running Unit and Integration Tests Separately and Publishing Both Results
Your team wants to implement automated testing in the build pipeline. You need to ensure that tests run and results are published. Which TWO tasks should you include?
⚠ Common exam trap
The trap is selecting tasks that seem related to testing but do not actually run or publish test results, such as Publish Build Artifacts or Azure PowerShell.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Visual Studio Test task
The Visual Studio Test task (C) is correct because it is the Azure Pipelines task that discovers and executes tests using the VSTest runner, which is exactly what is needed to run automated tests in the build pipeline. The Publish Test Results task (D) is correct because it takes the test result files produced by the test run and publishes them to the pipeline so results are surfaced in the build summary and reports, satisfying the requirement to publish results. The Publish Build Artifacts task (A) only uploads build outputs for later use and does not run or publish test results. The Copy Files task (B) merely copies files between directories and has no testing capability. The Azure PowerShell task (E) runs PowerShell scripts against Azure resources and is unrelated to executing or publishing test results.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Publish Build Artifacts task
Why it's wrong here
The Publish Build Artifacts task uploads build outputs (e.g., binaries, packages) to Azure Pipelines for downstream consumption or deployment, but it neither executes tests nor reads test result files. It is purely a file-staging mechanism, not a test runner.
- ✗
Copy Files task
Why it's wrong here
The Copy Files task copies files from a source directory to a destination on the build agent, commonly used to prepare deployment artifacts or organize outputs. However, it has no ability to invoke test frameworks, collect test outcomes, or generate test result reports, making it irrelevant for automated testing.
- ✓
Visual Studio Test task
Why this is correct
The Visual Studio Test task is the correct choice because it uses vstest.console.exe to run unit tests from test assemblies (MSTest, xUnit, NUnit) and produces test result data (e.g., TRX). It is the built-in Azure Pipelines task that actually executes tests during the build.
- ✓
Publish Test Results task
Why this is correct
The Publish Test Results task consumes test result files (TRX, JUnit, etc.) and uploads them to Azure Pipelines, making test summary, pass/fail rates, and coverage visible on the Tests tab. It typically runs after a test execution task like Visual Studio Test to report the outcome.
- ✗
Azure PowerShell task
Why it's wrong here
The Azure PowerShell task runs PowerShell scripts in an Azure authentication context for managing Azure resources or automating cloud operations. It lacks any integration with test frameworks and cannot emit standardized test result payloads for Azure Pipelines, so it is not intended for test automation.
Go deeper
Related to this question
Learn chapter
Implementing a Build Pipeline
Key term
Azure Pipelines
Azure Pipelines is a cloud-based CI/CD service from Microsoft that automatically builds, tests, and deploys code to any platform or cloud.
Key term
Pipeline
A pipeline is an automated series of steps that takes code from development to production, ensuring quality and speed.
About these practice questions
One of 696 original AZ-400 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
3 more ways this is tested on AZ-400
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. You are designing a build pipeline for a Node.js application. The team wants to ensure that the pipeline runs unit tests and publishes test results to Azure DevOps. Which task should you add to the pipeline?
easy- ✓ A.Publish Test Results task
- B.Copy Files task
- C.npm test
- D.Publish Build Artifacts task
Why A: The Publish Test Results task (A) is correct because it specifically ingests test result files (e.g., JUnit, NUnit, xUnit, or TRX formats) and publishes them to Azure DevOps, enabling test analytics, trend charts, and pass/fail reporting in the pipeline summary. For a Node.js application, after running unit tests with a framework like Jest or Mocha, the test results are typically output as JUnit XML files, and this task is required to make those results visible in the DevOps portal.
Variation 2. You need to run unit tests in your build pipeline and publish the test results to Azure Pipelines. Which task should you use?
easy- A.DotNetCoreCLI task with test command
- B.Npm task
- C.Publish Test Results task
- ✓ D.Visual Studio Test task
Why D: To run unit tests and publish the results in Azure Pipelines, use the Visual Studio Test task. It executes the tests and automatically publishes the test results to the pipeline, providing rich reporting and pass/fail analysis. The Publish Test Results task is only used when you already have test result files (e.g., JUnit, TRX) from a previous step and need to import them; it does not run any tests itself. The DotNetCoreCLI test command can also run and publish results, but the Visual Studio Test task is the standard framework-agnostic choice.
Variation 3. Which TWO tasks can be used to run unit tests in an Azure Pipeline?
easy- ✓ A.DotNetCoreCLI@2
- ✓ B.VSTest@2
- C.NuGetCommand@2
- D.PublishBuildArtifacts@1
- E.CopyFiles@2
Why A: The DotNetCoreCLI@2 task can run unit tests for .NET Core and .NET 5+ projects by invoking the 'dotnet test' command, which discovers and executes tests in the specified project files. The VSTest@2 task runs unit tests using the Visual Studio Test Runner, supporting a wide range of test frameworks (MSTest, xUnit, NUnit) and can run tests from assemblies or test containers. Both tasks are designed specifically for executing unit tests within an Azure Pipeline, making them the correct choices.
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Microsoft exam blueprint
This AZ-400 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-400 exam.