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
220
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
More Decks by John Blackbourn
See All by John Blackbourn
Investigating Regressions Quickly using Git Bisect
johnbillion
1
2.2k
WP CLI: An Intro and Interesting Use Cases
johnbillion
0
2k
Zen Mode: Developing While You're Offline
johnbillion
3
2.5k
An Explanation of HTTPS for the Inexperienced
johnbillion
0
1.7k
The A to Z of WordPress Multisite
johnbillion
3
2.2k
A Deep Dive into the Roles and Capabilities API
johnbillion
3
2.9k
A Layout Customiser for The Sun
johnbillion
4
470
Debugging as a Key Skill - WCSOF - WCMIL
johnbillion
1
1.9k
An Introduction to Character Encoding - WCNO - WCNL
johnbillion
0
2.1k
Other Decks in Technology
See All in Technology
少人数データチームのDevin活用実践事例
runandy16
2
440
深夜のクラウド懺悔室 1:29:300 or 1:0:0
kazzpapa3
0
180
AI時代のAPI品質を支えるガードレール / API Guardrails for API quality in the AI era
yokawasa
1
120
作り直せるコードは迅速に 作り直せないDBは慎重に - AI時代のプロダクトエンジニアが「判断の不可逆性」で開発速度を変える話
kinosuke01
0
250
AIで開発は速くなったのに、なぜ現場は楽にならないのか 〜あなたの組織のボトルネックを突き止めるワークショップ〜
jacopen
1
270
Bet AI Day 2026丨How We Bet AI: AIとともに働く場をつくる
layerx
PRO
2
2.4k
Redmine 7.0で私が開発した新機能の狙いと背景
vividtone
1
110
Webとヘルスデータ
yukukotani
0
190
20260903 Tokyo Jazug Night #62 | Azure エンジニアよ、 その環境は本当にセキュアか?
olivia_0707
1
620
Genie Code ワークショップ 応用編 / Genie-Code-Workshop-advanced
databricksjapan
PRO
0
350
生成AI時代の クレデンシャルとパーミッション設計
nrinetcom
PRO
3
1.5k
Sigmaユーザーのための有用リソース一挙公開 & Sigmaで使えるMCP #sigma_ucj /useful-resources-for-sigma-computing-users-and-mcps-with-sigma
shinyaa31
0
110
Featured
See All Featured
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Site-Speed That Sticks
csswizardry
13
1.5k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
230
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
470
Visualization
eitanlees
152
17k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Tell your own story through comics
letsgokoyo
1
1.1k
Are puppies a ranking factor?
jonoalderson
2
3.9k
The Spectacular Lies of Maps
axbom
PRO
1
970
Skip the Path - Find Your Career Trail
mkilby
1
220
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
690
Marketing to machines
jonoalderson
1
5.7k
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