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
Unit Testing: What? Why? How?
Search
John Blackbourn
February 14, 2017
Technology
0
170
Unit Testing: What? Why? How?
Slides from my talk at WP Hooked, February 2017.
https://www.meetup.com/wp_hooked/
John Blackbourn
February 14, 2017
Tweet
Share
More Decks by John Blackbourn
See All by John Blackbourn
Investigating Regressions Quickly using Git Bisect
johnbillion
1
2.1k
WP CLI: An Intro and Interesting Use Cases
johnbillion
0
2k
Zen Mode: Developing While You're Offline
johnbillion
3
2.3k
An Explanation of HTTPS for the Inexperienced
johnbillion
0
1.6k
The A to Z of WordPress Multisite
johnbillion
3
2k
A Deep Dive into the Roles and Capabilities API
johnbillion
3
2.6k
A Layout Customiser for The Sun
johnbillion
4
420
Debugging as a Key Skill - WCSOF - WCMIL
johnbillion
1
1.8k
An Introduction to Character Encoding - WCNO - WCNL
johnbillion
0
2.1k
Other Decks in Technology
See All in Technology
250905 大吉祥寺.pm 2025 前夜祭 「プログラミングに出会って20年、『今』が1番楽しい」
msykd
PRO
1
680
20250903_1つのAWSアカウントに複数システムがある環境におけるアクセス制御をABACで実現.pdf
yhana
3
540
Webアプリケーションにオブザーバビリティを実装するRust入門ガイド
nwiizo
6
740
生成AIでセキュリティ運用を効率化する話
sakaitakeshi
0
510
La gouvernance territoriale des données grâce à la plateforme Terreze
bluehats
0
150
企業の生成AIガバナンスにおけるエージェントとセキュリティ
lycorptech_jp
PRO
2
160
生成AI時代のデータ基盤設計〜ペースレイヤリングで実現する高速開発と持続性〜 / Levtech Meetup_Session_2
sansan_randd
1
150
AIのグローバルトレンド2025 #scrummikawa / global ai trend
kyonmm
PRO
1
260
CDK CLIで使ってたあの機能、CDK Toolkit Libraryではどうやるの?
smt7174
4
110
新アイテムをどう使っていくか?みんなであーだこーだ言ってみよう / 20250911-rpi-jam-tokyo
akkiesoft
0
150
Kiroと学ぶコンテキストエンジニアリング
oikon48
6
9.9k
Skrub: machine-learning with dataframes
gaelvaroquaux
0
120
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Designing for Performance
lara
610
69k
Gamification - CAS2011
davidbonilla
81
5.4k
The Art of Programming - Codeland 2020
erikaheidi
55
13k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
How GitHub (no longer) Works
holman
315
140k
Context Engineering - Making Every Token Count
addyosmani
1
30
Documentation Writing (for coders)
carmenintech
74
5k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
187
55k
A Tale of Four Properties
chriscoyier
160
23k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Transcript
Unit Testing: What? Why? How?
John Blackbourn WordPress core developer Working with WordPress for 10+
years Senior Engineer at Human Made @johnbillion
Unit Testing: What? Why? How?
You’re Going to L VE Unit Testing
That’s Enough of That
Unit Testing: What? Why? How?
A unit test is a piece of code which exists
only to verify expectations about the behaviour of another piece of code Verification
a.k.a. “Does my function do what I expect it to
do?”
A unit test operates in isolation in order to avoid
external interference Isolated
Tests typically run on the command line CLI
Tests are highly efficient because they're quickly repeatable Automated
Crossing your fingers and hoping… is not a unit test
Unit Testing: What? Why? How?
A unit test can cover many scenarios and never misses
anything Accuracy
Unit tests give you increased assurance that changes are less
likely to cause breakage Assurance
Unit tests give you confidence to make changes Confidence
Unit tests help you write better code Smaller functions Separation
of concerns Quality
Unit tests can be liberating Clarity
Unit Testing: What? Why? How?
None
None
None
None
“But I know that false isn’t true”
None
Arrange Act Assert AAA
Each time a WordPress test runs, it operates on a
fresh installation Remember
None
None
None
None
Accuracy Assurance Confidence Quality?… The Result
Assertions assertTrue( $actual ) assertFalse( $actual ) assertEquals( $expected, $actual
) assertCount( $expected, $actual ) assertObjectHasAttribute( $key, $actual ) assertArrayHasKey( $key, $actual ) assertWPError( $actual ) assertCanonical( $actual, $expected )
a.k.a. A Real World Gotcha Type Juggling Kills Me
None
None
WUT
None
Provide Verification Isolated Automated Recap
Accuracy Assurance Confidence Quality Recap
Arrange Act Assert Recap
I Hope You’ll Fall In L VE With Testing
Read the WordPress Unit Tests Visit PHPUnit website for reference
Check out WP-CLI scaffolding What Next?
John Blackbourn @johnbillion