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
230
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
Transcript
44 slides
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
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
2k
An Introduction to Character Encoding - WCNO - WCNL
johnbillion
0
2.2k
Other Decks in Technology
See All in Technology
常時稼働エージェントの作り方(Claude公式ブログを資料化)
minorun365
PRO
19
29k
IoTのデータ保存をSREの観点で考える
grimoh
1
120
RAGの改善を速く回すための評価基盤
yosukeyoshida
6
3.5k
ブース設計、 お前もプロダクトだったのか / So Booth Design Was a Product All Along
akihiro0038
0
150
E2E Test というハーネス — AI時代の自動テスト民主化
daishukojima
10
6k
「個社」ではなく「業界」の課題を解く AI 対話開発 ー 価値を広げる設計と、価値を守るエンジニアリング ー
ivry_presentationmaterials
4
850
メルカリの小規模チーム「Pod」で、 エンジニアがデータアナリストなしで、 AIを使ってデータ分析の自走を目指す取り組み
jackojacko_
1
340
gradle-best-practices 使ってみた
mikanichinose
0
220
データから見る AI時代のエンジニア転職と採用
junya_okura
4
1.2k
NutanixへのSSHアクセスの今後について
shadowhat
0
160
Kubernetes, Agones, WebRTC, GPU で作る クラウドゲーミング基盤を本番運用に乗せるまで
vivion
0
270
Context parameters で作る!はじめての型クラス
kworkdev
PRO
1
180
Featured
See All Featured
Scaling GitHub
holman
464
140k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
Testing 201, or: Great Expectations
jmmastey
46
8.4k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.9k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
Done Done
chrislema
187
17k
Optimising Largest Contentful Paint
csswizardry
37
4k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
520
A designer walks into a library…
pauljervisheath
211
25k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
3k