Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
How to Love Unit Testing
Search
Brian Bunke
April 12, 2018
Technology
42
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How to Love Unit Testing
Unit Testing in Pester
PowerShell Summit 2018
Brian Bunke
April 12, 2018
Other Decks in Technology
See All in Technology
PagerDuty Tech Hub-鳴らすけれど、人は動かない
ezaki
0
170
Temporal 最高!でも改めて「日付」について調べたら人類の負債すぎる件
riyaamemiya
0
140
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
140
エンタメ企業のM&Aを支えるデータ基盤 ― 統合から店舗のリアルタイム分析まで / Data Engineering Summit 2026
genda
0
170
触りたくないデータに、どう触るか AI時代のRBACアクセスガバナンス
ivry_presentationmaterials
0
260
実践! SRE × AI - ABEMA における AIOps -
tetsuya28
8
3.1k
Classmethod Company Deck
satoshi7
1
680
しろおびから始める!ログ活用の第一歩
shumei_ito
0
950
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
110
スプシの手作業からの解脱 ~更新はClaude Codeに、見せ方と使い方はGASアプリに任せる~
kentarofujii
0
150
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
190
1つのリクエストを追って理解する - llm-dのP/D分離
akhino
1
160
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
We Have a Design System, Now What?
morganepeng
55
8.4k
Prompt Engineering for Job Search
mfonobong
0
520
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
630
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2k
Leo the Paperboy
mayatellez
10
2.4k
Site-Speed That Sticks
csswizardry
13
1.6k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Abbi's Birthday
coloredviolet
4
10k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
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