AZ-400: Designing and Implementing Microsoft DevOps Solutions

Design and Implement Pipeline Automation

Local Tests Unit Tests Integration Tests Load Tests

In this article, we’ll cover four essential testing stages—local tests, unit tests, integration tests, and load tests—and show you how to plug them into your CI/CD workflows with Azure Pipelines. By automating these checks, you can catch defects early, maintain high quality, and ensure your services scale under pressure.

The image illustrates the importance of testing in the CI/CD process, featuring an infinity loop diagram with stages like code, build, release, deploy, and monitor.

Testing is crucial in CI/CD to maintain application quality and performance.

The image illustrates the importance of testing in CI/CD, featuring a person with a magnifying glass examining gears and a graph, symbolizing quality and performance assurance of applications.

Azure Pipelines provides the automation framework to execute these tests efficiently, ensuring smooth integration and deployment.

Testing Matrix

Test TypePurposeCommon Tools / Frameworks
Local TestsGet immediate feedback in the dev environmentShell scripts, IDE plugins
Unit TestsValidate individual methods or classesNUnit, JUnit
Integration TestsExercise interactions between modules and servicesdotnet test, pytest
Load TestsSimulate heavy traffic and measure performanceApache JMeter, BlazeMeter

Best Practice

Run local tests before every commit to minimize broken builds in your shared branches. Automate unit, integration, and load tests in separate pipeline stages for clear feedback and faster troubleshooting.

Local Tests

Local tests execute on your machine before code is pushed. They help catch syntax errors, style violations, and basic logical flaws without any external dependencies.

The image illustrates a process where changes are tested in a developer's environment before being pushed to a repository.

Benefits of Local Tests

The image highlights the benefits of local tests, featuring icons and text that emphasize "Quick Feedback" and "Reduced Build Failures."

  • Quick feedback loop
  • Fewer build failures in CI
  • Improved developer confidence

Unit Tests

Unit tests isolate and verify the smallest testable parts of your codebase. They run fast and serve as documentation for expected behavior.

The image illustrates the concept of unit testing using puzzle pieces, showing a real system with interconnected parts and a unit test isolating specific components. It highlights the focus on a particular method/unit and its dependencies.

FrameworkLanguageDocs
NUnit.NETnunit.org
JUnitJavajunit.org

The image is a comparison of two unit-testing frameworks: NUnit for .NET languages and JUnit for Java applications, used in Azure Pipelines.

Azure Pipelines YAML Examples

.NET with NUnit on Windows

trigger:
  - main

pool:
  vmImage: 'windows-latest'

steps:
  - task: NuGetToolInstaller@1

  - task: NuGetCommand@2
    inputs:
      restoreSolution: '**/*.sln'

  - task: VSBuild@1
    inputs:
      solution: '**/*.sln'
      platform: 'Any CPU'
      configuration: 'Release'

  - task: VSTest@2
    inputs:
      platform: 'Any CPU'
      configuration: 'Release'
      testSelector: 'testAssemblies'
      testAssemblyVer2: '**\test*.dll'
      searchFolder: '$(System.DefaultWorkingDirectory)'

Java with JUnit on Ubuntu

trigger:
  - main

pool:
  vmImage: 'ubuntu-latest'

steps:
  - script: sudo apt-get update && sudo apt-get install -y maven
    displayName: 'Install Maven'

  - script: mvn -B package --file pom.xml
    displayName: 'Build with Maven'

  - script: mvn test
    displayName: 'Run JUnit Tests'

Integration Tests

Integration tests validate that multiple components work together correctly. They are vital for catching interface mismatches and environment-specific issues.

The image illustrates integration testing using a Venn diagram, showing the overlap between Module A and Module B, with a note explaining that it combines modules to find interface defects.

Azure Pipelines Configuration

trigger:
  - main

pool:
  vmImage: 'ubuntu-latest'

variables:
  connectionString: $(DatabaseConnectionString)
  dbHost: $(DatabaseHost)
  dbUser: $(DatabaseUser)
  dbName: $(DatabaseName)
  dbPassword: $(DatabasePassword)

steps:
  - script: sudo apt-get update && sudo apt-get install -y postgresql-client
    displayName: 'Install PostgreSQL Client'

  - script: |
      PGPASSWORD=$(dbPassword) psql -h $(dbHost) -U $(dbUser) -d $(dbName) -a -f ./setup.sql
    displayName: 'Setup Database'

  - script: dotnet test --filter TestCategory=Integration
    displayName: 'Run Integration Tests'

  - script: |
      PGPASSWORD=$(dbPassword) psql -h $(dbHost) -U $(dbUser) -d $(dbName) -a -f ./cleanup.sql
    displayName: 'Cleanup Database'

Automated integration tests help catch mismatches early and keep your application’s components in sync.

Load Tests

Load tests simulate concurrent users to verify performance and scalability under stress. They help identify bottlenecks before they impact real users.

Tools such as Apache JMeter and BlazeMeter integrate seamlessly with Azure Pipelines.

The image describes configuring load tests in Azure Pipelines using Apache JMeter and BlazeMeter, highlighting their uses for simulating heavy loads and integrating cloud-based testing.

Choosing the Right Tool

The image is a guide for configuring load tests in Azure Pipelines, suggesting tool selection based on the application's technology stack, complexity of scenarios, and specific performance metrics. It includes a graphic of a checklist with a magnifying glass.

Select a load-testing solution based on:

  • Application architecture (microservices vs. monolith)
  • Scenario complexity (API calls, UI interactions)
  • Required metrics (response time, throughput, error rate)

Apache JMeter Example

trigger:
  - main

pool:
  vmImage: 'ubuntu-latest'

steps:
  - script: wget -q https://apache.mirrors.nublue.co.uk/jmeter/binaries/apache-jmeter-5.4.1.tgz
    displayName: 'Download JMeter'

  - script: tar -xzf apache-jmeter-5.4.1.tgz
    displayName: 'Extract JMeter'

  - script: |
      ./apache-jmeter-5.4.1/bin/jmeter -n -t load-test-plan.jmx -l results_file.jtl
    displayName: 'Run Load Tests'

  - script: |
      echo "Analyzing test results..."
      # Add your result analysis scripts here
    displayName: 'Analyze Test Results'

By automating load tests in your pipeline, you ensure your application meets performance benchmarks and scales reliably.

Watch Video

Watch video content

Previous
Integration of automated tests into pipelines