Courseiva
Design and implement build and release pipelinesmediumMultiple ChoiceObjective-mapped

Running Unit and Integration Tests Separately and Publishing Both Results

You are designing a build pipeline for a Java application that uses Maven. The build must run unit tests and integration tests separately. You want to publish test results to Azure Pipelines. Which task configuration should you use?

Quick Answer

Running Maven with separate 'test' and 'verify' goals in two distinct tasks keeps unit and integration tests genuinely independent, and pointing the Publish Test Results task at both runs' JUnit XML output lets Azure Pipelines merge them into one unified test summary — satisfying the requirement to run the suites separately while still reporting everything together.

⚠ Common exam trap

It's easy for candidates to assume a single Maven task with both goals can achieve separation, but Azure Pipelines executes all goals in one run, so the tests are not isolated; the correct approach requires two distinct tasks to enforce separate execution and independent result publishing.

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

Use two Maven tasks with goals 'test' and 'verify', and configure the Publish Test Results task to publish results from both runs.

It uses two separate Maven tasks with the 'test' and 'verify' goals, which allows unit tests and integration tests to run independently. The Publish Test Results task is then configured to consume the test result files (typically JUnit XML reports) from both runs, enabling Azure Pipelines to display a unified test summary. This approach aligns with the requirement to run unit and integration tests separately while still publishing all 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.

  • Use two Gradle tasks, one for unit tests and one for integration tests.

    Why it's wrong here

    Gradle task is for Gradle, not Maven.

  • Use a single Maven task with goals 'test verify', and configure the task to publish test results.

    Why it's wrong here

    Maven task does not have built-in test result publishing; need separate task.

  • Use two Maven tasks with goals 'test' and 'verify', and configure the Publish Test Results task to publish results from both runs.

    Why this is correct

    Correct: Maven can run tests and PublishTestResults can publish results.

  • Use two Visual Studio Test tasks, one for unit tests and one for integration tests.

    Why it's wrong here

    Visual Studio Test is for .NET, not Java.

About these practice questions

Courseiva writes every AZ-400 question from scratch — 823 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

6 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 configuring a release pipeline in Azure Pipelines for a Java application. The pipeline must run integration tests after deployment to a test environment and only proceed to production if tests pass. Which THREE should you configure?

hard
  • A.Use a pipeline condition on the production stage to run only if the test stage succeeded.
  • B.Set the agent job to run on the environment itself.
  • C.Set the integration test step to run only if the previous build succeeded.
  • D.Add a post-deployment gate that queries Azure Monitor for test failure signals.
  • E.Configure a post-deployment approval for the production stage.

Why A: To run integration tests after deployment to a test environment and only proceed to production if tests pass, configure a pipeline condition on the production stage to run only if the test stage succeeded (A) and add a post-deployment gate that queries Azure Monitor for test failure signals (D). Option E is incorrect because a post-deployment approval on the production stage occurs after the production deployment has already happened, so it does not prevent the deployment. Option B is incorrect because agent jobs run on agents, not directly on environments. Option C is incorrect because the integration test step should run after deployment, not based on the previous build success.

Variation 2. 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.

Variation 3. 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 4. 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?

easy
  • A.Publish Build Artifacts task
  • B.Copy Files task
  • C.Visual Studio Test task
  • D.Publish Test Results task
  • E.Azure PowerShell task

Why C: The correct tasks are Visual Studio Test task (option C) which runs the tests, and Publish Test Results task (option D) which publishes the test results to Azure Pipelines. Option A (Publish Build Artifacts) publishes build outputs but not test results. Option B (Copy Files) copies files between locations and does not run tests. Option E (Azure PowerShell) runs PowerShell scripts and is not for testing.

Variation 5. Your build pipeline for a Java application uses Maven. You need to run unit tests and integration tests separately. Unit tests should run on every commit, while integration tests should run only when the build is triggered by a pull request to the main branch. How should you configure the pipeline?

easy
  • A.Add both test types as steps in the same job and use a step condition.
  • B.Create two separate stages: one for unit tests, one for integration tests.
  • C.Create two jobs: one with unit tests (always), one with integration tests conditioned on 'eq(variables['Build.Reason'], 'PullRequest')'.
  • D.Use a single job with both tests, but set the 'always()' condition on the integration test step.

Why C: A correct configuration must run integration tests only for pull requests targeting the main branch. This requires checking both Build.Reason == 'PullRequest' and System.PullRequest.TargetBranch == 'refs/heads/main'. None of the provided options include the target branch check, so none is fully correct as written. While option A allows a step condition that could include the target branch, the option itself does not specify it. Option C is also missing the target branch check and would incorrectly run for PRs to other branches.

Variation 6. 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.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.