Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
How to Love Unit Testing
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Brian Bunke
April 12, 2018
Technology
0
41
How to Love Unit Testing
Unit Testing in Pester
PowerShell Summit 2018
Brian Bunke
April 12, 2018
Tweet
Share
Other Decks in Technology
See All in Technology
Bill One 開発エンジニア 紹介資料
sansan33
PRO
5
18k
Phase04_ターミナル基礎
overflowinc
0
2.4k
AgentCoreとLINEを使った飲食店おすすめアプリを作ってみた
yakumo
2
250
Physical AI on AWS リファレンスアーキテクチャ / Physical AI on AWS Reference Architecture
aws_shota
1
130
スピンアウト講座03_CLAUDE-MDとSKILL-MD
overflowinc
0
1.3k
20260323_データ分析基盤でGeminiを使う話
1210yuichi0
0
180
テストプロセスにおけるAI活用 :人間とAIの共存
hacomono
PRO
0
160
Phase11_戦略的AI経営
overflowinc
0
1.6k
JEDAI認定プログラム JEDAI Order 2026 受賞者一覧 / JEDAI Order 2026 Winners
databricksjapan
0
340
Phase06_ClaudeCode実践
overflowinc
0
2k
私がよく使うMCPサーバー3選と社内で安全に活用する方法
kintotechdev
0
110
How to install a gem
indirect
0
1.6k
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
340
58k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
180
Color Theory Basics | Prateek | Gurzu
gurzu
0
260
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
HDC tutorial
michielstock
1
590
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
75
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
330
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
Google's AI Overviews - The New Search
badams
0
950
Discover your Explorer Soul
emna__ayadi
2
1.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
Transcript
How to Love Unit Testing Brian Bunke @brianbunke
Pester “Pester is the ubiquitous test and mock framework for
PowerShell.” https://github.com/pester/Pester @brianbunke
Common Questions Am I doing this right? What does a
good test even look like? What’s not enough, or too much? @brianbunke
Today’s Goals 1. Feel comfortable reading and writing unit tests
2. Know some future pitfalls to watch out for @brianbunke
Why Love Test Suites? •Fully automated •Self-documenting •Allows support to
scale •Improves code reviews @brianbunke
Integration Tests @brianbunke
Integration Testing Pain Points • Require infrastructure • Slow •
Service interruptions • Order of tests matters • Root cause isolation @brianbunke
Falling in Love
What is Unit Testing? 1. Making your test suite discrete
2. Isolating external dependencies from your tests • “Mocking” @brianbunke
How would you prepare to give a presentation? @brianbunke
DEMO Integration Test to Unit Test Mock 101 @brianbunke
Don’t Fall in Love on the First Date
2 Unit Tests, 0 Integration Tests @brianbunke
Integration Tests -- We’re Still Friends! You should know if
an API has changed …eventually Limit, don’t eliminate @brianbunke
Unit Test “Drawback” #1: Testable Code Mocking works with functions
(and modules) Writing tests makes you write more testable code @brianbunke
DEMO Keep your code testable One function = one purpose
@brianbunke
Unit Test Drawback #2: Parameter Types If unit testing isolates
third-party dependencies, strongly typing our parameters is an issue @brianbunke
DEMO Isolate third-party dependencies to private functions @brianbunke
Unit Test Drawback #3: “Tryhard” Mode Strive for “black box”
over “white box” Tests are meant to help maintain and refactor Accept that bugs will always exist @brianbunke
DEMO Unit testing our new module’s functions Using Mock -ParameterFilter
@brianbunke
Limitations of ParameterFilter Mocks • Parameters must be explicitly named
• Common names may collide with Pester internals • Use $PSBoundParameters instead @brianbunke
Unit Test Drawback #4: Consistency Unit tests are optimistic about
breaking changes, but we also need to look inward. @brianbunke
Consistency Tests Large pull requests happen Human code reviews are
fallible @brianbunke
Negative Tests @brianbunke
DEMO oops Because you should say “oops” before you deploy,
not after @brianbunke
Making Your Love Last @brianbunke
How Can You Love Unit Tests? @brianbunke
How Can You Love Unit Tests? Write as few of
them as possible. @brianbunke
How Can You Love Unit Tests? •Trust is freeing •Fast
•Independent •Repeatable @brianbunke
How to Keep Loving Unit Tests • Single responsibility functions
• Strongly typing parameters from dependencies? • Push everything possible toward the module level • When in doubt, keep it simple • Consider Test-Driven Development (TDD) @brianbunke
xUnit Test Patterns Gerard Meszaros Practical Test Pyramid https://martinfowler.com/ articles/practical-test-pyramid.html
@brianbunke
Pester Resources https://github.com/pester/Pester/wiki @brianbunke
PowerShell Summit Resources • Today’s talk • https://github.com/brianbunke/PesterUnitTesting2018 • 2018,
Glenn Sarti • https://speakerdeck.com/glennsarti • 2017, Chris Hunt • https://github.com/cdhunt/pssummit2017-mocking • 2016, June Blender • https://youtu.be/jvvh9cpD_LM @brianbunke
THANK YOU! Please use the event app or Sched.com to
submit a session rating! @brianbunke brianbunke.com speakerdeck.com/brianbunke