9 Testing ARM templates

 

This chapter covers

  • Writing tests to validate your code
  • Choosing the best test scenario for your infrastructure
  • Using different tools to test and validate your templates
  • Writing custom tests using Pester and PowerShell
  • Running tests in your Azure DevOps pipeline

When writing software these days, it is common to also write tests. One of the main reasons for writing tests is to verify that the code works when you write it and that the code still works after making changes later on. You write tests to build confidence that a change does not negatively impact the quality of the code and that the software is ready for deployment into production.

The same applies to testing Infrastructure as Code. When you’re talking about writing software tests, you might be introduced to what is called the test pyramid. It describes various forms of testing and shows that each has its pros and cons. The layers within this pyramid can differ from application to application, depending on how you build yours. A simple example is shown in figure 9.1. In this pyramid, you see three layers: unit tests, integration tests, and UI tests. You could have more layers in your scenario; for example, you might add performance testing.

Figure 9.1 The testing pyramid for software

9.1 Static analysis and validation

9.1.1 Visual Studio Code extensions

9.1.2 Validation using PowerShell or Azure CLI

9.1.3 ARM template test toolkit

9.1.4 Custom tests using Pester

9.2 Unit tests

9.3 Integration tests

9.4 End-to-end tests

9.5 Pester in CI/CD

Summary

sitemap