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
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
3k
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.2k
Other Decks in Technology
See All in Technology
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
2
830
全人類(ほぼ)AWS Organizations の上でAWSを利用している、その世界を知る話
htan
1
130
生成AIと進める探索的データ分析(2026.10.03 第122回Tokyo.R勉強会)
tatamiya
2
1.5k
3つのアプローチで目指す チームを強くするAI駆動開発
thkt
0
150
宣言型部分更新は何を解決しどこへ向かうのか
shuta13
0
310
go-sqletch
moznion
0
130
おそらく日本で唯一のDevRelインターン生として
husengs7
0
170
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
380
FactoryBotアンチパターン / factory_bot anti-patterns
toshimaru
0
150
AI時代のPRレビューにどう向き合うか?
kairim0
1
170
ファミコンでPHPを動かす / PHP on the Famicom side b
tomzoh
0
140
OpenSharing について熱く語る〜AI アセットの共有について〜
kameitomohiro
0
260
Featured
See All Featured
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
300
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
A better future with KSS
kneath
240
18k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
The untapped power of vector embeddings
frankvandijk
2
1.9k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
Test your architecture with Archunit
thirion
2
2.4k
WCS-LA-2024
lcolladotor
0
870
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Code Reviewing Like a Champion
maltzj
529
40k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
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