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
220
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
17
Vertrauen in Teams & Führung
oliverklee
0
120
Software-Qualität von TYPO3-Extensions automatisieren
oliverklee
0
7
Vertrauen in Teams & Führung
oliverklee
0
82
Testing von TYPO3-Extensions
oliverklee
0
16
Software-Qualität von Extensions automatisieren
oliverklee
1
10
Content-Synchronisierung
oliverklee
0
88
Gewaltfreie Kommunikation: ein Crashkurs
oliverklee
0
210
Motivationspsychologie und Gamification in Non-Profit-Organisationen
oliverklee
0
120
Other Decks in Programming
See All in Programming
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
350
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
150
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
130
良いユニットテストを書こう
mototakatsu
8
3.1k
Effective Signals in Angular 19+: Rules and Helpers
manfredsteyer
PRO
0
130
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
180
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
8
1.9k
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
110
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
530
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
390
MCP with Cloudflare Workers
yusukebe
2
230
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Automating Front-end Workflow
addyosmani
1366
200k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Done Done
chrislema
182
16k
The Cult of Friendly URLs
andyhume
78
6.1k
Mobile First: as difficult as doing things right
swwweet
222
9k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Product Roadmaps are Hard
iamctodd
PRO
50
11k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Embracing the Ebb and Flow
colly
84
4.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