The Pester Book (retired)
The Pester Book (retired)

Retired

This book is no longer available for sale.

The Pester Book (retired)

This book is 70% complete

Last updated on 2017-02-20

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 https://leanpub.com/pesterbook, and Adam can be contacted there (on the “Email the Author” section) or on Twitter @adbertram.

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 PowerShell.org 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. You can find him on Twitter @concentratedDon, or on his website, DonJones.com. 

Adam Bertram
Adam Bertram

Adam Bertram is a 20-year veteran of IT and experienced online business professional. He’s an entrepreneur, IT influencer, Microsoft MVP, blogger, trainer and content marketing writer for multiple technology companies. Adam is also the founder of the popular IT career development platform TechSnips. Catch up on Adam’s articles at adamtheautomator.com, connect on LinkedIn, or follow him on Twitter at @adbertram or the TechSnips Twitter account at @techsnips_io.

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

Authors have earned$8,245,744writing, publishing and selling on Leanpub,
earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.

Learn more about writing on Leanpub

The Leanpub 45-day 100% Happiness Guarantee

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

See full terms

Free Updates. Free App. 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), EPUB (for phones and tablets), MOBI (for Kindle) and in the free Leanpub App (for Mac, Windows, iOS and Android). 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. It really is that easy.

Learn more about writing on Leanpub