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
Test-driven development with PHPUnit
Search
Oliver Klee
August 04, 2023
Programming
0
170
Test-driven development with PHPUnit
Oliver Klee
August 04, 2023
Tweet
Share
More Decks by Oliver Klee
See All by Oliver Klee
Content-Synchronisierung
oliverklee
0
21
Gewaltfreie Kommunikation: ein Crashkurs
oliverklee
0
62
Motivationspsychologie und Gamification in Non-Profit-Organisationen
oliverklee
0
83
Writing PHPUnit tests for TYPO3 extensions
oliverklee
0
150
Software quality for TYPO3 projects: A story of cheese, games and tools
oliverklee
0
220
TDD für Senior-Devs
oliverklee
0
64
Gamification für Arbeit in Communities
oliverklee
0
110
Software quality, cheese and games
oliverklee
0
300
Test-driven development with PHPUnit
oliverklee
0
270
Other Decks in Programming
See All in Programming
ONE WEDGE_company_guide
1wedge_one
0
500
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
9
4.1k
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
780
Tailwind CSSを本気でカスタマイズする方法
fsubal
14
5.3k
Node.js v22 で変わること
yosuke_furukawa
PRO
9
3.5k
Goのエラースタックトレースの歴史と今後
sonatard
9
1.6k
TYPO3 v13 – The road to LTS: What's new and new APIs
luisasofie_xoxo
0
210
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
280
Zero Waste, Radical Magic, and Italian Graft – Quarkus Efficiency Secrets
hollycummins
0
230
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
Behind VS Code Extensions for JavaScript / TypeScript Linnting and Formatting
unvalley
5
1k
GitHub Copilotのススメ
marcy731
1
200
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
267
39k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
6
1.5k
Optimizing for Happiness
mojombo
370
69k
Design by the Numbers
sachag
274
18k
Why You Should Never Use an ORM
jnunemaker
PRO
51
8.6k
Git: the NoSQL Database
bkeepers
PRO
422
63k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
2
1.3k
Rails Girls Zürich Keynote
gr2m
91
13k
Typedesign – Prime Four
hannesfritz
36
2.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
79
43k
Clear Off the Table
cherdarchuk
84
310k
Designing the Hi-DPI Web
ddemaree
276
33k
Transcript
Test-driven Development with PHPUnit Oliver Klee, 2023-08 @
[email protected]
|
[email protected]
About me Oliver „Oli“ Kle e #bon n #extension-de v
#workshop-teache r #unit-testing-gu y #phpstan-gu y #best-practices-tea m #motivation-research-tea m #team-leadership-working-grou p #game-cookin g #powermetal
Unit Tests?
Manual testing is cumbersome
Automated testing is fast
Unit tests for the TYPO3 Core
Unit Tests 406 (144) tests/s
Functional Tests 8.13 (1.97) tests/s
Acceptance Tests .009 (.003) tests/s
Verify that your code does what you expect
Make sure that your changes won‘t break anything
Keep others from breaking your code
Don’t break anything even in complex projects
Create a safety net for refactoring or for TYPO3, PHP
or Symfony updates
Improve the structure of your code
Find the location of bugs
Green feels good!
Let’s get some terms straight
The two programming modes clean hacky
Testsuite Testcase Test Assertion Test Test Testcase
The life cycle of a test new FooTest(); setUp(); /**
@test */ lifeIsGood(); tearDown();
4 test phases set up setUp() code in the test
method exercise method call verify assert…() tear down tearDown()
Code test-first write test write code refactor
Effects of TDD higher code coverage minimale code think
before you code tests now test what the code should do (instead of what it does) focused coding cleaner code structure
Test levels http:// fi lipdefar.com/2015/06/tested-be-thy-name.html
Unit tests are small and fast
Integration tests test how components work together in TYPO3:
„functional tests“
Acceptance tests Codeception Cypress
Test types
Blackbox tests test the public API
Whitebox tests inner workings test the
Anti- zombie tests-
Regression tests
Smoke tests
Smoke tests
Story tests for Behavior-driven developmen t (BDD) Behat Codeception
The testing pyramid Unit Functional/ Integration Acceptance Photo by Eugene
Tkachenko on Unsplash: https://unsplash.com/photos/TF47p5PHW18
Naming Tests
Use meaningful test names classCanBeInstantiated setTitleSetsTitle setSizeWithZeroThrowsException hasTitleForEmptyTitleReturnsFalse Name the
behavior. Name the preconditions. Name the method. Don’t use “works” or “works correctly”. measureFrubbleWorksCorrectly