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
210
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.4k
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
460
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
第3回しろおびセキュリティスポンサーセッション
log0417
0
120
『モンスターストライク』 の運営に伴走する! データ民主化への 解析グループの3つのアプローチ
mixi_engineers
PRO
0
220
システム監視入門
grimoh
5
810
SmartHR Engineering Team Deck
smarthr
0
170
[ChatGPT Work LT]事務作業が苦手な人のための バックオフィスの「半」自動化
chimaki_iot
0
140
実践が先生だった— 新卒サーバーエンジニア1年目のリアル
mixi_engineers
PRO
0
250
toio・myCobotでフィジカルAIっぽいことを行うための検討(とりあえず調査) / フィジカルAI LT(IoTLTによる開催)
you
PRO
0
270
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
10
3.7k
オートロックマンションなのに、各部屋は施錠なし!? 攻撃者が組織内ネットワークで大暴れする理由 / The Front Door Is Locked, but the Rooms Are Wide Open: Why Attackers Move Freely Inside Enterprise Networks
nttcom
0
1.5k
メルカリのグローバルアプリで挑んだ AlloyDB 運用と課題解決の実践記
hatappi
0
140
OSPN.JPバージョンアップ作業進捗のご報告 / 20260801-osc26kyoto
akkiesoft
0
210
CloudWatchから始めるAWS監視
butadora
0
320
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Embracing the Ebb and Flow
colly
88
5.1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
380
Build your cross-platform service in a week with App Engine
jlugia
234
19k
How GitHub (no longer) Works
holman
316
150k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Six Lessons from altMBA
skipperchong
29
4.4k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
270
The SEO identity crisis: Don't let AI make you average
varn
0
520
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
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