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
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
250
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
4
3.5k
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
300
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
220
アクセシビリティから考える情報設計
high_g_engineer
0
390
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
330
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
8.2k
Webの地図
yosuke_furukawa
PRO
6
4.7k
スマート反転とウェブアクセシビリティ
camiha
0
210
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
360
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
300
Agents on Rails - Rails at Scale 2026
irinanazarova
0
180
Featured
See All Featured
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
460
HDC tutorial
michielstock
2
880
Speed Design
sergeychernyshev
33
2.1k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
260
Mobile First: as difficult as doing things right
swwweet
225
10k
The Language of Interfaces
destraynor
162
27k
Building an army of robots
kneath
307
46k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
460
Amusing Abliteration
ianozsvald
1
310
Thoughts on Productivity
jonyablonski
76
5.4k
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できる • 効果 ◦ 仕様変更に強い ◦ スイッチングコスト低減 ◦
設計力の強化