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
230
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
29
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
100
Testing von TYPO3-Extensions
oliverklee
0
25
Software-Qualität von Extensions automatisieren
oliverklee
1
14
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
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
14
4.8k
Drawing Heighway’s Dragon- Recursive Function Rewrite- From Imperative Style in Pascal 64 To Functional Style in Scala 3
philipschwarz
PRO
0
150
読まないコードリーディング術
hisaju
0
110
新宿駅構内を三人称視点で探索してみる
satoshi7190
2
120
Generating OpenAPI schema from serializers throughout the Rails stack - Kyobashi.rb #5
envek
1
420
⚪⚪の⚪⚪をSwiftUIで再現す る
u503
0
100
Djangoにおける複数ユーザー種別認証の設計アプローチ@DjangoCongress JP 2025
delhi09
PRO
4
500
やっと腹落ち「スプリント毎に動くモノをリリースする」〜ゼロから始めるメガバンクグループのアジャイル実践〜
sasakendayo
0
120
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
1.1k
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
8
1.5k
Webフレームワークとともに利用するWeb components / JSConf.jp おかわり
spring_raining
1
130
1年目の私に伝えたい!テストコードを怖がらなくなるためのヒント/Tips for not being afraid of test code
push_gawa
1
650
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
1.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
How STYLIGHT went responsive
nonsquared
99
5.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
Unsuck your backbone
ammeep
669
57k
How to Think Like a Performance Engineer
csswizardry
22
1.4k
4 Signs Your Business is Dying
shpigford
183
22k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
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