Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
レガシーシステムに自動テストを導入する第一歩 / 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.4k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
レガシーシステムに自動テストを導入する第一歩 / 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.7k
Other Decks in Programming
See All in Programming
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
140
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
670
パーソナライズPodcastを作った話
repunit11
0
120
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
540
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
13
6.6k
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
250
カツオ、ご期待ください
suneo3476
0
150
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
390
Are APIs Still Relevant in the AI Era?
soyuka
0
420
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
プロダクトコードからライブラリの境界を見つける
elmetal
PRO
0
100
phperだってパンチカードでコーディングしたい
o0h
PRO
0
200
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
My Coaching Mixtape
mlcsv
0
340
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
350
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
Color Theory Basics | Prateek | Gurzu
gurzu
1
480
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Into the Great Unknown - MozCon
thekraken
41
2.8k
It's Worth the Effort
3n
188
29k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
Chasing Engaging Ingredients in Design
codingconduct
0
340
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
970
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
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できる • 効果 ◦ 仕様変更に強い ◦ スイッチングコスト低減 ◦
設計力の強化