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
140
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
1.9k
Zen Mode: Developing While You're Offline
johnbillion
3
2.2k
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
400
Debugging as a Key Skill - WCSOF - WCMIL
johnbillion
1
1.8k
An Introduction to Character Encoding - WCNO - WCNL
johnbillion
0
2k
Other Decks in Technology
See All in Technology
AWSLambdaMCPServerを使ってツールとMCPサーバを分離する
tkikuchi
1
2.2k
さくらの夕べ Debianナイト - さくらのVPS編
dictoss
0
180
ペアーズにおけるData Catalog導入の取り組み
hisamouna
0
270
大AI時代で輝くために今こそドメインにディープダイブしよう / Deep Dive into Domain in AI-Agent-Era
yuitosato
1
260
50人の組織でAIエージェントを使う文化を作るためには / How to Create a Culture of Using AI Agents in a 50-Person Organization
yuitosato
6
3.2k
やさしいMCP入門
minorun365
PRO
146
95k
Startups On Rails 2025 @ Tropical on Rails
irinanazarova
0
250
Webアプリを Lambdaで動かすまでに考えること / How to implement monolithic Lambda Web Application
_kensh
7
1.2k
От ручной разметки к LLM: как мы создавали облако тегов в Lamoda. Анастасия Ангелова, Data Scientist, Lamoda Tech
lamodatech
0
180
プロダクト開発におけるAI時代の開発生産性
shnjtk
2
190
ゆるくVPC Latticeについてまとめてみたら、意外と奥深い件
masakiokuda
2
230
MCPを活用した検索システムの作り方/How to implement search systems with MCP #catalks
quiver
1
560
Featured
See All Featured
Making Projects Easy
brettharned
116
6.1k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.7k
How GitHub (no longer) Works
holman
314
140k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
227
22k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Rails Girls Zürich Keynote
gr2m
94
13k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.2k
Designing for Performance
lara
607
69k
Designing for humans not robots
tammielis
252
25k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
104
19k
Statistics for Hackers
jakevdp
798
220k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
13
660
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