The Pester Book (retired)


This book is no longer available for sale.

The Pester Book (retired)

About the Book

This book has been retired, and Adam is now working on it on his own. You can find the “replacement” book at, and Adam can be contacted there (on the “Email the Author” section) or on Twitter @adbertram.

  • Share this book

  • Categories

    • PowerShell
    • Testing
  • Installments completed

    16 / 26

  • Feedback

    Email the Author(s)

About the Authors

Don Jones
Don Jones

Don Jones has been in the IT industry since the mid 1990s, and has been a recipient of Microsoft's "Most Valuable Professional" Award since 2003. He's a co-founder of and The DevOps Collective, and a Curriculum Director for online video training company Pluralsight. Don authored some of the first books ever published for Windows PowerShell, and is the co-author of Learn Windows PowerShell in a Month of Lunches, the bestselling entry-level book for PowerShell. Don's a sought-after speaker at technology conferences like Microsoft Ignite, TechMentor, and many more. In 2014, Don started writing fiction in the sci-fi and fantasy genres, and had produced several notable novels, including The Never: A Tale of Peter and the Fae, The Achillios Chronicles trilogy (Alabaster, Onyx, and Verdant), and Daniel Scratch: A Story of Witchkind. You can find him on Twitter @concentratedDon, or on his website, 

Adam Bertram
Adam Bertram

Adam Bertram is a 20+ year veteran of IT and an experienced online business professional. He’s a consultant, Microsoft MVP, blogger, trainer, published author and content marketer for multiple technology companies. Catch up on Adam’s articles at, connect on LinkedIn, or follow him on Twitter at @adbertram.

Table of Contents

    • About This Book
    • About the Author
    • Foreword
    • Feedback
    • Code Samples
    • Introduction
      • Testing as Institutional Memory
      • Testing Drives Better Modularization
      • Tests as Functional Specifications
      • Tests in Automated Build Pipelines
      • Automated Testing!
      • Where We’re Not Going
  • Part 1: Meet Pester
    • Pester Concepts
      • Tests
      • Mocks
      • Assertions
      • Scaffolding
      • TestDrive
    • Designing for Testing
      • Input is Via Parameters
      • Output is Via the Pipeline
      • Actions Aren’t Output
      • Tightly Scoped Commands are Easiest to Test
      • A Word for DSC Resource Authors
    • Describe and Context Blocks
      • A Describe is a Scope
      • A Describe Can be Tagged
      • A Describe Contains…
    • Before and After Blocks
    • It Blocks
      • Examples
      • The Actual Test
    • Should
      • Be and BeExactly
      • BeLessThan, BeGreaterThan
      • Wildcard Comparisons: BeLike, BeLikeExactly; Match, MatchExactly
      • Object Type: BeOfType
      • Errors: Throw
      • Objects Exist: Exist
      • Strings in Files: Contain, ContainExactly
      • Nothing: BeNullOrEmpty
      • BeIn (an Array)
      • Remember: Should is a Command That Can Throw Exceptions
    • Test Cases
      • Creating Tests for Different Parameters
      • Using the TestCases parameter
      • Using the Test Name Token
      • Test Cases Have Many Uses
    • Mocks
      • Mocking Specific Object Types
      • Mock Scope
      • Module-Level Mocks
      • Parameter Filters
      • Verifying Mocks
    • The TESTDRIVE: Drive
      • Referencing Test Drive as a PSDrive
      • Referencing TestDrive as a Variable
  • Part 2: Using Pester
    • Design Practices
      • Testing is a Forever Thing
      • Dealing with Modules and Dot-Sourced Scripts
      • The Input/Execution/Output Pattern
      • Naming Conventions
      • Tagging
    • Adding Tests For a Function
      • Understand the Subject
      • Designing Tests
      • Writing the Test
      • Future Iterations
      • Comparing to Warren’s Tests
      • Wrapping Up
    • Adding Tests - Again
      • The Code
      • Analyzing the Code
      • Refactoring the Code for Testability
      • Limiting Function Input
      • Writing the Tests
      • Wrapping Up
    • Working with Pester Output
    • Infrastructure Validation
      • Infrastructure Validation in Pester
      • Analyzing the Code
      • Getting Testing Dependencies in Place
      • Prototyping the Tests
      • Writing the Infrastructure Tests
      • Dependencies
      • Building Dependency Discovery Code
      • Adding Dependency Checking to Tests
      • Switching it Up
    • Mocking the Unmockable
      • Methods
      • Wrapping Up
    • Cross-Platform Pester
    • Testing GUI Scripts
    • Troubleshooting Tests
  • Part 3: Code Coverage
    • Why Code Coverage?
      • Code Coverage Metrics
      • So… Why Code Coverage?
      • The Test Case Tie-In
    • Using Pester to Measure Code Coverage
      • A Simple Code Coverage Test
      • Getting Granular with Code Coverage
    • Improving Code Coverage
      • Start Here
      • Analyzing Code Coverage
    • A Pester Case Study
      • Background
      • TO BE CONTINUED…..
  • Part 4: Pester Cookbook
    • Recipe: Testing for Live Conditions
      • The Recipe
      • The Background
    • Recipe: Testing Scheduled Tasks
      • The Recipe
      • The Background
    • Recipe: Testing for Installed Software
      • The Recipe
      • The Background
    • Recipe: Ensuring all Functions in a Module Have Tests
      • The Recipe
      • The Background
    • Recipe: Testing Scheduled Tasks
      • The Recipe
      • The Background
    • Recipe: Testing External Applications
      • Testing Exit Codes from EXE Files In Scripts
      • The Background
      • Testing Exit Codes from Standalone EXE files
      • The Background
    • Recipe: Common Tests for Functions and Modules
      • The Recipe
      • The Background
    • Recipe: Testing Script Blocks
      • The Recipe
      • The Background
    • Release Notes

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub