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
240
Test-driven development with PHPUnit
Oliver Klee
August 04, 2023
Tweet
Share
More Decks by Oliver Klee
See All by Oliver Klee
Team-Management-Plattform
oliverklee
0
30
Vertrauen in Teams & Führung
oliverklee
0
160
Software-Qualität von TYPO3-Extensions automatisieren
oliverklee
0
10
Vertrauen in Teams & Führung
oliverklee
0
110
Testing von TYPO3-Extensions
oliverklee
0
26
Software-Qualität von Extensions automatisieren
oliverklee
1
15
Content-Synchronisierung
oliverklee
0
110
Gewaltfreie Kommunikation: ein Crashkurs
oliverklee
0
240
Motivationspsychologie und Gamification in Non-Profit-Organisationen
oliverklee
0
140
Other Decks in Programming
See All in Programming
研究開発と実装OSSと プロダクトの好循環 / A virtuous cycle of research and development implementation OSS and products
linyows
1
160
Lambdaの監視、できてますか?Datadogを用いてLambdaを見守ろう
nealle
2
960
アーキテクトと美学 / Architecture and Aesthetics
nrslib
8
1.2k
Compose Navigation実装の見通しを良くする
hiroaki404
0
120
CSC486 Lecture 14
javiergs
PRO
0
140
PHPでお金を扱う時、終わりのない 謎の1円調査の旅にでなくて済む方法
nakka
0
530
Duke on CRaC with Jakarta EE
ivargrimstad
0
1k
iOSでQRコード生成奮闘記
ktcryomm
2
190
PromptyによるAI開発入門
ymd65536
1
320
なぜselectはselectではないのか
taiyow
2
170
ローコードサービスの進化のためのモノレポ移行
taro28
1
240
❄️ NixOS/nixpkgsにSATySFiサポートを実装する
momeemt
2
160
Featured
See All Featured
Designing for Performance
lara
605
69k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
176
52k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Gamification - CAS2011
davidbonilla
80
5.2k
Statistics for Hackers
jakevdp
797
220k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
2.9k
Embracing the Ebb and Flow
colly
84
4.6k
Automating Front-end Workflow
addyosmani
1369
200k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.2k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.5k
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