The Pester Book
The Pester Book (Pester Book (Forever Edition))
Minimum price
Suggested price
The Pester Book

This book is 100% complete

Completed on 2018-10-18

About the Book

"Pester is an important skill that every PowerShell user should master."
- Jeffrey Snover, Creator of PowerShell

Pester is a unit-testing framework for PowerShell, and perhaps the first open-source software product that ships with Windows itself! Author Adam Bertram will walk you through the Pester philosophy, syntax, and numerous real-world examples in this "Agile-published" book.

Part 1, which is complete as a v1 release, covers the core syntax of Pester, and introduces you to various possible use cases for the different syntax elements. It's enough to get you up and running if you're familiar with unit testing, or if you want to give Pester a spin.

Part 2 will take that syntax and dig into the world of unit testing and Test-Driven Development, through a series of real-world walkthroughs. Some of these will be "stream of consciousness," following the actual process someone might use to add or develop Pester tests. This Part will also cover using Pester for infrastructure validation in an "infrastructure from code" environment.

Part 3 will introduce you to Gherkin. Gherkin is another style of test writing that comes with Pester. This part will introduce you to Gherkin, how it's different than Pester test design and how it integrates with Pester.

Part 4 will tackle cover coverage, an important topic to help make sure you're testing all of your code.

Part 5 will be more of a "cookbook," with recipes for testing specific types of situations. This will probably be one area of the book that we continually build over time, based in large part on reader feedback.

Chapters in these parts will be released as we write them, so you won't need to wait for an entire part to be completed. And, I'll continue to expand and revise released chapters based on reader feedback - which is very welcome! Readers who purchase the book are notified of how to contact the authors directly, and you can also reach out on Twitter @adbertram.

See the Contents

Use the "Table of Contents" link to see the complete table of contents for the full book. This does change and evolve as I work on the book.

I Publish as I Go

This is an Agile-published book, which means the author is releasing it as it's written, and will continue to update the book as the underlying technology evolves over time. This is the last book you'll ever need to buy on this topic, because your one-time purchase grants you lifetime access to updates and new content. I'll even email you via LeanPub (if you opt-in) when there's fresh content for you.

Check Out the Free Sample

The free sample includes sample chapters, but why bother? LeanPub has a no-questions-asked refund policy, so it's completely risk-free to grab the "real" book and see what you think.

What Formats are Available?

All LeanPub books are offered in PDF, MOBI, and EPUB, and you get all three with your purchase. Note that the PDF is probably the "highest fidelity" version, especially in terms of code listings.

How Can I Contact the Author?

I love feedback. Use the "Email the Author" link, just below, to contact me. For feedback on the book, please provide a chapter, heading, and short snippet of text to let me know where you're looking - page numbers don't do any good, as they don't correspond with our source files.

About the Author

Adam Bertram
Adam Bertram

Adam Bertram is an Senior Automation Engineer, technical writer, trainer, and presenter. Adam specializes in consulting and evangelizing all things IT automation. Adam is a Microsoft Windows Cloud and Datacenter Management MVP focused on the PowerShell language and various DevOps tooling in the Microsoft ecosystem. He authors IT pro course content for Pluralsight, is a regular contributor to numerous print and online publications and presents at various user groups and conferences.

Reader Testimonials

Nicholas Getchell
Nicholas Getchell

I just finished this book last night. I've been using Pester for a while but still earned a ton.

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
    • Describe Blocks
      • Scopes
      • Tagging
      • What Makes a Describe Block
    • Before and After Blocks
    • It Blocks
      • Pending and Skipped States
      • Set-TestInconclusive
      • 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: FileContentMatch and FileContentMatchExactly
      • 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
      • Mock Assertions
      • Asserting A Single Mock
      • Wrap Up
    • 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
      • Choosing When to Create Describe Blocks
      • Naming Conventions
      • Tagging
      • Summary
    • 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
      • nUnit XML
      • Returning Failed Tests as Exit Codes
      • Wrap Up
    • 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
    • Mocking the Unmockable
      • .NET Methods
      • Wrapping Up
    • Troubleshooting Tests
      • Mocking
  • Part 3: Using Gherkin with Pester
    • Gherkin Introduction
      • Files
      • Syntax
      • Running Gherkin Tests
  • Part 4: 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
  • Part 5: Pester Cookbook
    • Recipe: Testing for Live Conditions
      • The Recipe
    • Recipe: Testing Scheduled Tasks
      • The Recipe
    • Recipe: Testing for Installed Software
      • The Recipe
    • Recipe: Ensuring all Functions in a Module Have Tests
      • The Recipe
    • Recipe: Testing Scheduled Tasks
      • The Recipe
    • Recipe: Testing External Applications
      • Testing Exit Codes from EXE Files In Scripts
      • The Background
      • Testing Exit Codes from Standalone EXE files
    • Recipe: Testing Syntax
      • The Recipe
    • Recipe: Testing Remote Script Blocks
      • The Recipe
    • Other Resources
      • Learning Pester
      • Using Pester
    • Release Notes

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...

Write and Publish on Leanpub

Authors, publishers and universities use Leanpub to publish amazing in-progress and completed books and courses, just like this one. You can use Leanpub to write, publish and sell your book or course as well! 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