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
130
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
1.9k
WP CLI: An Intro and Interesting Use Cases
johnbillion
0
1.9k
Zen Mode: Developing While You're Offline
johnbillion
3
2k
An Explanation of HTTPS for the Inexperienced
johnbillion
0
1.5k
The A to Z of WordPress Multisite
johnbillion
3
1.8k
A Deep Dive into the Roles and Capabilities API
johnbillion
3
2.4k
A Layout Customiser for The Sun
johnbillion
4
380
Debugging as a Key Skill - WCSOF - WCMIL
johnbillion
1
1.6k
An Introduction to Character Encoding - WCNO - WCNL
johnbillion
0
1.9k
Other Decks in Technology
See All in Technology
ServiceNow Knowledge Learning Rise up
manarobot
0
210
Hands-on Gemini, the Google DeepMind LLM
meteatamel
1
110
AOAI をきっかけに 社内の Azure 管理を見直した話
recruitengineers
PRO
1
270
Terraformあれやこれ/terraform-this-and-that
emiki
8
1.4k
web-application-security
matsuihidetoshi
0
160
障害対応をちょっとずつよくしていくための 演習の作りかた
heleeen
0
140
20240416_devopsdaystokyo
kzkmaeda
1
220
Compose Compiler Metricsを使った実践的なコードレビュー
tomorrowkey
1
220
SIEMを用いて、セキュリティログ分析の可視化と分析を実現し、PDCAサイクルを回してみた
coconala_engineer
0
280
Java EE/Jakarta EEの現状と将来―クラウドネイティブ時代にJava EEは対応できるのか?―
takakiyo
1
150
オーナーシップを持つ領域を明確にする
konifar
13
3.1k
エンジニア候補者向け資料2024.04.24.pdf
macloud
0
3.3k
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
20
1.9k
Making the Leap to Tech Lead
cromwellryan
124
8.5k
VelocityConf: Rendering Performance Case Studies
addyosmani
320
23k
Being A Developer After 40
akosma
57
580k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Building a Scalable Design System with Sketch
lauravandoore
456
32k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Creatively Recalculating Your Daily Design Routine
revolveconf
210
11k
Building Better People: How to give real-time feedback that sticks.
wjessup
355
18k
Stop Working from a Prison Cell
hatefulcrawdad
266
19k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3k
Done Done
chrislema
178
15k
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