AZ-400 Question 110
Select 2Your team is building a microservices-based .NET Core application. You have an Azure DevOps pipeline that must run unit tests in the Build stage with code coverage enabled. Then, you must run integration tests in a separate stage that is triggered automatically if the Build stage completes successfully. You also want to ensure that any test failures fail the entire pipeline. Which two actions should you implement to meet these requirements?
- A
In the Build stage, add a 'DotNetCoreCLI@2' task with the 'test' command and enable code coverage.
- B
Configure the pipeline to continue on test failures in the Build stage so the integration tests can still run.
- C
Create a separate IntegrationTest stage that depends on the successful completion of the Build stage and define tasks for integration testing there.
- D
Use a manual trigger or approval gate to start integration tests after a successful Build stage.
Show answer and explanation
Correct answers: A, C
Explanation
A best-practice DevOps testing strategy involves running quick unit tests in the Build stage with code coverage to catch issues early, then running more extensive integration tests in a separate stage. Azure DevOps supports tasks like 'DotNetCoreCLI@2' for test execution and code coverage, and you can chain stages to automatically trigger integration tests only if the Build stage passes. This aligns with Microsoft DevOps best practices as described in the Azure DevOps documentation on implementing multi-stage pipelines and automated testing (docs.microsoft.com/azure/devops/pipelines).
- A. Correct.
Option 1 is correct because using the 'DotNetCoreCLI@2' task with the 'test' command while enabling code coverage in the Build stage ensures unit tests are automatically run, coverage is gathered, and failures will fail the stage if configured properly.
- B. Incorrect.
Option 2 is incorrect because allowing the pipeline to continue on test failures defeats the purpose of automated quality checks and does not align with failing the pipeline on test errors. Proper practice is to fail the pipeline if critical tests fail.
- C. Correct.
Option 3 is correct because creating a distinct IntegrationTest stage that depends on the Build stage ensures a streamlined workflow: integration tests only run if the Build stage completes successfully. This aligns with best practices for separating unit tests and integration tests into dedicated stages.
- D. Incorrect.
Option 4 is incorrect because requiring a manual trigger or an approval gate for integration tests undermines continuous integration principles. The requirement states the tests should be triggered automatically after a successful build, not manually.