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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
AIの性能が向上しても未解決な組織の重大問題は何か?/An Unsolved Organizational Problem in the Age of AI
moriyuya
0
150
AI-DLCを活用した高品質・安全なAI駆動開発実践 / AI Driven Development with AI-DLC
yoshidashingo
0
150
Claude code Orchestra
ozakiomumkj
3
1k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
50k
Djangoユーザが知っ得なPostgreSQL機能 - 設計の選択肢を増やす / Djang-use-PostgreSQL
soudai
PRO
0
210
AWSシリコン最前線 〜AI時代のチップ選択を読み解く〜
htokoyo
1
200
AI フレンドリーなエラー監視を TypeScript で実現する
shinyaigeek
2
270
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.9k
GoとSIMDとWasmの今。
askua
3
510
protovalidate-es を導入してみた
bengo4com
0
140
2026.06.13_AI時代に事業会社が「SIer出身エンジニア」を求める理由 / Why Businesses Seek Engineers with a System Integrator Background in the AI Era
jumtech
0
800
Agentic Web
dynamis
1
180
Featured
See All Featured
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
The Pragmatic Product Professional
lauravandoore
37
7.3k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
WCS-LA-2024
lcolladotor
0
620
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
550
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
160
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
Six Lessons from altMBA
skipperchong
29
4.3k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
190
Mind Mapping
helmedeiros
PRO
1
240
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
Done Done
chrislema
186
16k
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