Tuesday, 3 July 2018

Testing Azure Automation Runbooks using Pester

If you’re using Azure Automation Runbooks for automation, you may find yourself writing code that is not testable. To test your code, it needs to be in functions. Sure, you should break out all of your repeatable, reusable code into functions and save them as separate Runbooks, or a collection of functions that you can “Dot source” into your other Runbooks.

But, Runbooks really are functions, they are just not declared as functions. You have a single file, that accepts parameters, and executes code.

That is a function! Let’s make it testable.

Take this Runbook: Test-Script.ps1

And this Pester Test Test-Script.tests.ps1

The Pester Tests will generate this temporary file, which can be dot-sourced in as a function:


6 comments:

  1. Thank you for your valuable content , Easy to understand and follow. As said, the migration to cloud is very essential for the protection of the database.

    Cloud Migration services
    Aws Cloud Migration services
    Azure Cloud Migration services
    Vmware Cloud Migration services
    Database Migration services
    Lia Infraservices

    ReplyDelete
  2. Nice way to test the code, thanks!

    ReplyDelete
  3. Looking for a pipe cutting machine in your area ? Then we are the best for you, who suit your expectations. We have huge experience in this field. We are 100% dedicated to finding you a high quality pipe cutting machine.
    If you want to know more, Please check out Cheers Electronic Technical Co.LTD: https://www.terminal-crimping.com/Pipe-Tube-Cutting-Tools.html

    ReplyDelete