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
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
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
550
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.2k
設計次第でAIコードの読む量は減らせる / designing-for-code-reading
minodriven
20
6.5k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
670
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
410
The Rails Doctrine Decade
koic
2
410
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
110
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
360
Verilogで学ぶCPU自作入門.pdf
uyuki234
8
3.7k
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
390
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3.3k
Featured
See All Featured
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
560
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
340
It's Worth the Effort
3n
188
29k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
550
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
270
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
Evolving SEO for Evolving Search Engines
ryanjones
0
300
Faster Mobile Websites
deanohume
310
32k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Practical Orchestrator
shlominoach
192
12k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
250
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できる • 効果 ◦ 仕様変更に強い ◦ スイッチングコスト低減 ◦
設計力の強化