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
190
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
40
Gewaltfreie Kommunikation: ein Crashkurs
oliverklee
0
130
Motivationspsychologie und Gamification in Non-Profit-Organisationen
oliverklee
0
94
Writing PHPUnit tests for TYPO3 extensions
oliverklee
0
180
Software quality for TYPO3 projects: A story of cheese, games and tools
oliverklee
0
260
TDD für Senior-Devs
oliverklee
0
72
Gamification für Arbeit in Communities
oliverklee
0
110
Software quality, cheese and games
oliverklee
0
340
Test-driven development with PHPUnit
oliverklee
0
300
Other Decks in Programming
See All in Programming
はしめてのプログラミングとロボット制御
watawatavoltage
0
290
AHC035解説
terryu16
0
710
ドメイン駆動設計の実践
masuda220
PRO
17
5.2k
Jetpack for KMP
fornewid
1
290
Clean Architecture by TypeScript & NestJS
ryounasso
0
150
HMSコンペ 11th Solution (team : kansai-kaggler)
t88
1
680
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
140
Rustのweb開発を助ける 便利なツール紹介
yuki0418
1
190
GraphQL はいいぞ! ~Laravel で学ぶ GraphQL 入門~
azuki
1
160
Rust.Nagoya #1
codemountains
0
170
Play Billing Library 7.0.0 変更点まとめ@potatotips#88
kako351
0
160
Xcode 16のPreviewModifierと@Previewableを活用した効率的なプレビュー方法の考察
ojun9
2
160
Featured
See All Featured
Debugging Ruby Performance
tmm1
71
11k
It's Worth the Effort
3n
181
27k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
13
430
ReactJS: Keep Simple. Everything can be a component!
pedronauck
662
120k
Building a Scalable Design System with Sketch
lauravandoore
458
32k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
36
9.1k
Speed Design
sergeychernyshev
9
270
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
248
12k
RailsConf 2023
tenderlove
16
720
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
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