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
レガシーシステムに自動テストを導入する第一歩 / 2020-phpcon-tdd-in-leg...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
takaram
December 12, 2020
Programming
3.3k
1
Share
レガシーシステムに自動テストを導入する第一歩 / 2020-phpcon-tdd-in-legacy-product
PHPカンファレンス2020で行ったLTのスライドです
takaram
December 12, 2020
More Decks by takaram
See All by takaram
楽をするためのPHPDocと配列型の落とし穴 / PHPDoc and pitfalls of array
takaram
3
5.6k
Other Decks in Programming
See All in Programming
Kubernetes上でAgentを動かすための最新動向と押さえるべき概念まとめ
sotamaki0421
3
560
YJITとZJITにはイカなる違いがあるのか?
nakiym
0
220
Cache-moi si tu peux : patterns et pièges du cache en production - Devoxx France 2026 - Conférence
slecache
0
280
JOAI2026 1st solution - heron0519 -
heron0519
0
140
Back to the roots of date
jinroq
0
290
Making the RBS Parser Faster
soutaro
0
460
AWS re:Invent 2025の少し振り返り + DevOps AgentとBacklogを連携させてみた
satoshi256kbyte
3
170
PicoRuby for IoT: Connecting to the Cloud with MQTT
yuuu
2
630
10 Tips of AWS ~Gen AI on AWS~
licux
5
430
Running Swift without an OS
kishikawakatsumi
0
850
Vibe NLP for Applied NLP
inesmontani
PRO
0
450
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
130
Featured
See All Featured
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.5k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
800
Paper Plane
katiecoart
PRO
1
49k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
310
Java REST API Framework Comparison - PWX 2021
mraible
34
9.3k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
280
Accessibility Awareness
sabderemane
1
100
Building the Perfect Custom Keyboard
takai
2
730
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
110
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.9k
Transcript
レガシーシステムに自動テストを 導入する第一歩 PHP Conference Japan 2020
自己紹介 • 名前 ◦ 荒巻 拓哉 • 所属 ◦ 株式会社ラクス
◦ メール配信サービス「配配メール」の開発 ◦ 新卒2年目
None
2007年サービス開始 立派なレガシープロダクト
課題 • PHPUnitを約1年前から一部で導入開始 しかし • 導入はなかなか進まない • 既存機能のテストを書く時間は取れない
とある案件で テスト駆動開発& 既存ロジックのリファクタリング してみた話
案件の内容 「従来の機能をAPIでも実行できるようにしたい」 API 従来:画面操作で実行 APIで同じ操作を実行
対象の機能 • データの登録・更新機能 • 現状 ◦ テストコードなし ◦ コントローラにロジックをべた書き ▪
600行超えの神メソッド……
実装戦略 1. 画面のテストを作成 2. オールグリーンになるのを確認 3. コントローラのロジックを部品化 4. APIのテストを作成 5.
3.の部品でAPIを実装
実装戦略 1. 画面のテストを作成 2. オールグリーンになるのを確認 3. コントローラのロジックを部品化 4. APIのテストを作成 5.
3.の部品でAPIを実装 既存ロジックの リファクタリング テスト駆動で新機能の 実装
実装戦略 1. 画面のテストを作成 2. オールグリーンになるのを確認 3. コントローラのロジックを部品化 4. APIのテストを作成 5.
3.の部品でAPIを実装 • コントローラを呼び出す機能テスト ◦ in: リクエストパラメータ ◦ out: DBの更新結果
実装戦略 1. 画面のテストを作成 2. オールグリーンになるのを確認 3. コントローラのロジックを部品化 4. APIのテストを作成 5.
3.の部品でAPIを実装 テストが失敗しないか確認しながら
実装戦略 1. 画面のテストを作成 2. オールグリーンになるのを確認 3. コントローラのロジックを部品化 4. APIのテストを作成 5.
3.の部品でAPIを実装 • 実際にリクエストを送信 (Guzzle) • DBの更新結果を確認
実装戦略 1. 画面のテストを作成 2. オールグリーンになるのを確認 3. コントローラのロジックを部品化 4. APIのテストを作成 5.
3.の部品でAPIを実装 • テスト作成と並行 • 一通り実装したら即テスト実行
こうして実装が完了 めでたしめでたし……
_人人人人人人人人人_ > 突然の仕様変更 <  ̄Y^Y^Y^Y^Y^Y^Y^Y^Y ̄
自動テストの効果 • 仕様変更に強い ◦ 開発終盤で仕様変更が発生しても、テストがあるので 安心してコードを修正できる
その他の効果 • スイッチングコスト低減 ◦ 実装 → 手動テスト → 修正 はスイッチングコスト高
◦ 実装後すぐにテスト結果がわかると楽 • チームの設計力強化 ◦ テストしやすさを考慮した設計が身につく
まとめ • レガシープロダクトでもTDDできる • 効果 ◦ 仕様変更に強い ◦ スイッチングコスト低減 ◦
設計力の強化