r/PowerShell • u/nkasco • Dec 10 '25
Question How Often Do You Write Pester tests?
Topic, genuinely curious.
20
Upvotes
r/PowerShell • u/nkasco • Dec 10 '25
Topic, genuinely curious.
10
u/jippeenator Dec 10 '25
I've done a few recently. They are useful for ensuring functions in the code act as expected after editing and before committing.
The pester tests can be modified as you go to ensure new conditions are accounted for.
They provide some reassurance, so maybe I'll use them more moving forward.
8
u/raip Dec 10 '25
When developing, typically only when I'm doing something complicated.
Operationally, all the time. Pretty much every time I install or make some infrastructure change I'm writing a pester test for it. I support over a thousand servers at this point and operational tests to validate the environment makes my life possible.
3
u/psdarwin Dec 10 '25
I work on a few large internal PowerShell modules in our company. We write Pester tests for every function (hundreds of functions), and tests on the modules. We actually have a module level test that verifies all functions have Pester tests, so you can't deploy a new version without having unit tests everywhere.
Pester tests create confidence. When you have unit tests on a function, you can feel confident doing all sorts of refactoring, knowing that if your tests are well written and still pass, your changes aren't breaking changes.
So I am a big proponent of Pester testing
2
u/ron3090 Dec 10 '25
I try to write tests any time a script will make changes to a system. They’re not really needed when I’m just gathering information, but they’re crucial when I want to ensure the changes are done right.
2
u/BlackV Dec 10 '25
Gonna be honest, no enough, no where near it
2
u/PanosGreg Dec 10 '25
Same here as u/BlackV , I write pester tests very rarely.
In fact, I use them for a very specific reason, to do integration testing only
That means I never use them for unit testing, as-in I never write mock functions, so I never check how a function works internally, but rather if it works as expected.
I almost always use Pester tests to check if the resulting system is in the desired state or if it is in a ready (as-in expected state). Which means that the system under test (the so-called SUT), needs to be present, which means in my case most of the times I cannot just run the test on my laptop, but rather I need to execute it on the real system (which has access to stuff, which runs the actual service, which has dependencies and they need to be available, etc)
2
u/PutridLadder9192 Dec 10 '25
I used to have a test for every function but I found I only used the useful ones so I mainly just use pester when I know I'm going to be doing something tricky and iterating a bunch to get it right. I been doing this so long that my brain is like an interpreter I can read anything that isn't complex and know what will happen.
2
u/heyitsgilbert Dec 10 '25
Pretty much every day. From simple unit tests to more complex integration tests to even weirder dynamic tests. They provide confidence that your code works the way it's supposed to.
Run into an edge case? Write the test, see it fail, fix the bug, see it succeed. I'm less worried about total code coverage, but quick unit tests give a good positive signal.
The number of times I kick myself for not writing a basic test that would have caught the very obvious bug is embarrassingly high. Eventually you start to realize it's worth it to just start there.
Check out all of Glenn Sarti's talks on Pester.
It's why I donate monthly to the Pester org. Without a testing framework I wouldn't rely on the language. https://opencollective.com/pester
2
u/dathar Dec 10 '25
....never...
Usually swimming in work. Wishing there's time for these fancy checking and testing processes but my modules usually don't change too much or all my output tests are manual.
2
u/Theratchetnclank Dec 12 '25
A lot. We have loads of custom modules which all require pester unit tests.
1
u/blooping_blooper Dec 10 '25
I've never done it. It's been on my list to look into, but never had time to actually do so.
1
u/ExceptionEX Dec 11 '25
Literally never, if I'm going to do TDD I'll do it in c#. I use power shell for quick and dirty scripting, I do data validation. But doing unit testing
1
u/[deleted] Dec 10 '25
[removed] — view removed comment