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
200
Test-driven development with PHPUnit
Oliver Klee
August 04, 2023
Tweet
Share
More Decks by Oliver Klee
See All by Oliver Klee
Vertrauen in Teams & Führung
oliverklee
0
3
Testing von TYPO3-Extensions
oliverklee
0
2
Software-Qualität von Extensions automatisieren
oliverklee
1
3
Content-Synchronisierung
oliverklee
0
59
Gewaltfreie Kommunikation: ein Crashkurs
oliverklee
0
170
Motivationspsychologie und Gamification in Non-Profit-Organisationen
oliverklee
0
100
Writing PHPUnit tests for TYPO3 extensions
oliverklee
0
200
Software quality for TYPO3 projects: A story of cheese, games and tools
oliverklee
0
290
TDD für Senior-Devs
oliverklee
0
81
Other Decks in Programming
See All in Programming
もう実家に手頃な情シス娘は不要!Bedrockでもう一人の娘を作る
komakichi
0
120
WEBアプリケーションにおけるAWS Lambdaを用いた大規模な非同期処理の実践
delhi09
PRO
7
4.4k
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
740
Vue :: Better Testing 2024
up1
1
410
クラウドサービスの 利用コストを削減する技術 - 円安の真南風を感じて -
pyama86
3
400
Modern Angular with Lightweight Stores: New Rules and Options
manfredsteyer
PRO
0
110
文化が生産性を作る
jimpei
3
580
2024-10-02 dev2next - Application Observability like you've never heard before
jonatan_ivanov
0
180
Memory API: Patterns, Use Cases, and Performance
josepaumard
1
180
実践Dash - 手を抜きながら本気で作るデータApplicationの基本と応用 / Dash for Python and Baseball
shinyorke
2
640
Програмиране с Rust, ФМИ, 2024
nikolads
0
110
Beyond Laravel Octane - Hyperf for Laravel Artisans
albertcht
1
140
Featured
See All Featured
KATA
mclloyd
28
13k
GraphQLとの向き合い方2022年版
quramy
43
13k
What's in a price? How to price your products and services
michaelherold
243
11k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
41
9.2k
Navigating Team Friction
lara
183
14k
Code Reviewing Like a Champion
maltzj
519
39k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
327
21k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
A Philosophy of Restraint
colly
203
16k
The Pragmatic Product Professional
lauravandoore
31
6.2k
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