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
Amazon ECS ネットワークモード選びに悩まない ~検証を通じて見えたネットワークモードの選び方~ / 20261114 Masaki Okuda
shift_evolve
PRO
2
170
AWS Blocksで AIエージェント作れるの知ってます?
kmiya84377
1
170
40以上のマイクロサービスを支えるKubernetes JITアクセス — 160以上の恒久RoleBindingを削減
jumpe1
0
120
ポケモンバトルのAIエージェント
koji_kawamura
0
330
NutanixへのSSHアクセスの今後について
shadowhat
0
190
データ界隈LT祭の運営のふりかえり
yoshimura_datam
0
120
メディアアートを〈拡張〉する——器官学と個体化論を手がかりに
_kotobuki_
1
420
AWS Well-Arhitected Frameworkセキュリティの柱 について
miu_crescent
PRO
2
280
セキュリティチームは どのコンテナイメージの脆弱性対応を優先すべきか 〜CISA新指針とSCCで作る脆弱性トリアージ〜
swdtkuy
0
380
エンタープライズIAMについて - ID・権限をどう統制するか
oidfj
1
370
AIエージェントの認証がまとめて進化! ~pre:Inventで来た3つのアップデート~
minorun365
PRO
2
300
ブース設計、 お前もプロダクトだったのか / So Booth Design Was a Product All Along
akihiro0038
0
200
Featured
See All Featured
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
620
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
540
Documentation Writing (for coders)
carmenintech
77
5.7k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.8k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.6k
Designing for Performance
lara
612
70k
Evolving SEO for Evolving Search Engines
ryanjones
0
380
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.8k
Test your architecture with Archunit
thirion
2
2.5k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
860
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.8k