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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
JAWS-UG 東京支部が始める、JAWS-UG支部コラボ / JAWS-UG lunchtime LT Collaboration
y0hgi
0
170
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
370
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
250
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
270
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.2k
Java 27新機能 / Java 27 new features
kishida
2
190
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
450
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
740
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
370
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
320
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
310
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
190
Featured
See All Featured
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Are puppies a ranking factor?
jonoalderson
2
4k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
340
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
580
A designer walks into a library…
pauljervisheath
211
25k
Building AI with AI
inesmontani
PRO
1
1.3k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
4 Signs Your Business is Dying
shpigford
187
23k
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できる • 効果 ◦ 仕様変更に強い ◦ スイッチングコスト低減 ◦
設計力の強化