131: PowerShell BDD with Pester with Adam Bertram
with Adam Bertram
About this episode
Today we’ll be test talking about Pester with Adam Bertram, author of multiple Pluralsight courses on PowerShell, and founder of AdamTheAutomator.com. I’m a big believer in the fact that infrastructure code — just like test automation code — should follow the same rigor as your application code.
Pester is a unit testing framework that was built for people who want to take their PowerShell scripts and modules to whole different level, and really apply professional unit testing abilities to it.
If your or your team is performing any type of PowerShell development, you won’t want to miss this episode.
Quotes & Insights from this Test Talk
- Pester is, as you said, a unit testing framework specifically for the PowerShell language. It was a framework built for people who want to take their PowerShell scripts and modules and such to a different level, and really apply professional unit testing abilities to PowerShell. Traditionally, PowerShell has just been known as a scripting language, but nowadays, a lot of companies are really depending on the code that's written in PowerShell for production, mission-critical things. Pester was built as a result of that to make sure to run tests against all those scripts and modules and all the orchestration that takes place, that PowerShell does to allow you to treat PowerShell as more of, as I refer to it, a “big boy" language. Instead of a “Yeah, yeah, yeah, that's nice" scripting language, taking PowerShell to a more professional language.
- Pester is it can be essentially just built with PowerShell. You can test a number of different things. It's a unit testing framework, so you can test the code in that script, or the module, but you can also do various integration or even acceptance testing with it. In a sense, it can do infrastructure testing, as well. It can make sure that the script that you just ran placed a file in a specific spot, make sure it got all the dependencies; it goes back and test the environment that way. It can be a really good tool, not only to do your unit testing, but also your integration testing and, what I like to refer to as “infrastructure testing," which is to make sure your infrastructure is configured to how you think it should be.
- Pester is not quite as robust as a lot of other testing frameworks. Again, I came from an Ops background; I've never actually been a software developer, per se; but, yes, Pester does have assertions, it has mocking capabilities, and it has a lot of the things that you traditionally use with other unit testing framework
- I've used mocking extensively in my unit tests. It's really easy to do. All it is in Pester mock, is just a script block, a PowerShell script block. You just define it with your mock keyword, say “Mock" and then the function name.One of the things in Pester I really like is that it understands scoping. If you have a private function in your PowerShell module, you can actually define mocks and they understand your private functions, so it understands module scopes, script scope, and a lot of that stuff. As far as I know, it has a majority of the mocking functions, so you can define mocks, you can assert mocks, or call, you can do various parameter filters. If a PowerShell function was Call with a specific set of parameters, you could define a mock, versus not define a mock, and that sort of thing.
- Since Pester comes out of the box with Windows now – I believe it comes with Windows 10, and I think it comes with server 2016, now – so you have a version of Pester already on a Windows box. In order to get it, Pester is just a PowerShell module, and if you don't have a PowerShell module, you have PowerShell v.4 or later, you can use PowerShell Git.
- Considering the majority of the audience, as far as I'm concerned, in the community that I know, a lot of people are still brand new to Pester. As a result, there's a lot of newbies out there, and there's a lot of people that I've seen are really, really scared of Pester. It's either from Ops personnel, or even developers are like “Why do we need to test PowerShell?" I would say, if somebody is not using Pester today, the best place to go would be Pluralsight – there is a really good course on unit testing with Pester by Robert Cain; mine's coming out pretty soon. I've also done some articles on www.4sysops.com . I did seven or eight articles in a series on Pester, on getting started from the ground up, where you know nothing at all about Pester, and learning the concepts of unit testing, and how to apply those concepts to Pester. You can find those at sysops.com/members/adam-bertram . You can also check out my website, www.adamtheautomator.com.
Resources
Connect with Adam Bertram
- Twitter: @adbertram
- Blog: AdamTheAutomator
- Adam's PluralSight Courses
May I Ask You For a Favor?
Thanks again for listening to the show. If it has helped you in any way, shape or form, please share it using the social media buttons you see on the page.
Additionally, reviews for the podcast on iTunes are extremely helpful and greatly appreciated! They do matter in the rankings of the show and I read each and every one of them.

Test Talks is sponsored by the fantastic folks at Sauce Labs. Try it for free today!
Keep listening
Related episodes

Automation Testing Podcast · Ep. 609
Why Your AI Tests Pass When Your Features Fail with Donovan Brady
with Donovan Brady
Why Your AI Tests Pass When Your Features Fail? Donovan Brady of Leapwork shows how to make
Oct 27

Automation Testing Podcast · Ep. 608
Scary Test Automation POCs Made Easy: Halloween Special With Paul Grossman
with Paul Grossman
Running a proof of concept on test automation tools can feel like a horror movie. Vendors promise
Oct 20

Automation Testing Podcast · Ep. 607
Locust and Azure Load Testing: Create and Debug Load Tests with AI with Lars Holmberg and Abhinav Premsekhar
with Lars Holmberg and Abhinav Premsekhar
Performance testing has never been easier to start, or more important to get right. As teams ship
Oct 6

Automation Testing Podcast · Ep. 606
AI Agents Passed the Tests. Real Devices Didn’t. with Nick Metcalfe
with Nick Metcalfe
Cloud device farms make it easy to get started with real device testing. But what happens when
Sep 29