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
What is TDD?
Search
浦川仁成
September 25, 2024
Programming
1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
What is TDD?
新規PJでTDDを導入することになったので、チームメンバーにTDDのメリットを説明するため、ChatGPTにMarpでスライドを作ってもらいました。
浦川仁成
September 25, 2024
Transcript
12 slides
テスト駆動開発( TDD)について ソフトウェア開発における手法 1
テスト駆動開発( TDD)とは? TDD( Test Driven Development) は、ソフトウェアの機能をテストケースから始 める開発手法 3つのステップで進行: i.
テストを書く ii. コードを書く iii. リファクタリング 2
TDDのメリット コードの品質が向上する バグが早期に発見されやすい 小さなステップで開発が進むため、修正が容易 設計が洗練される 3
TDDの 3つのサイクル 1. Red: 失敗するテストを書く 2. Green: テストを通すために最小限のコードを書く 3. Refactor:
コードを整理し改善する 4
Red: 失敗するテストを書く まず、期待する動作を定義するテストを書きます。 // calculator_test.go package calculator import "testing" func
TestAdd(t *testing.T) { result := Add(2, 3) expected := 5 if result != expected { t.Errorf("expected '%d', but got '%d'", expected, result) } } 5
Green: 最小限のコードを書く 意図的にバグのあるコードを書き、テストが失敗することを確認します。 // calculator.go package calculator func Add(a, b
int) int { return a - b // 足し算ではなく、間違って引き算を実装 } この時点でテストは失敗します。これが TDDによってバグが早期に発見される例 です。 6
テスト失敗の確認 テストを実行すると、以下のエラーが表示されます: calculator_test.go:10: expected '5', but got '-1' テストがバグを早期にキャッチしました。バグがプロダクション環境に入る前に 修正可能です。
7
Green: 正しいコードを書く バグを修正して、正しい足し算を行うコードにします。 // calculator.go package calculator func Add(a, b
int) int { return a + b } 8
Refactor: コードを整理する テストが通ったら、コードの重複や無駄を取り除き、整理します。 リファクタリングの例はここでは省略しますが、機能を壊さないように注意しつつコ ードの改善を行います。 9
TDDのメリット : バグの早期発見 TDDを使用することで、コードを書いてすぐにテストが実行されるため、バグが 早期に発見されやすくなります。 例えば、間違ったコードを書いたとしても、テストがすぐに失敗を教えてくれま す。 バグが本番環境に入る前に修正できるので、品質が大幅に向上します。 10
まとめ TDDの 3つのサイクル Red: テストを書く Green: コードを書く Refactor: コードを改善する 継続的にテストを作成・実行することで、安定した品質のコードを提供できま
す。 11
最後に TDDは最初は難しく感じるかもしれませんが、繰り返すことで強力な開発手法に なります。 最初の一歩はテストを書くことから始めましょう! 12
More Decks by 浦川仁成
See All by 浦川仁成
Java GOLD認定者がGoに浮気した話
urakawa_jinsei
0
43
Raycastを使いこなせ!
urakawa_jinsei
0
140
Other Decks in Programming
See All in Programming
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
840
Debian JP Projectのサーバー構成
uwabami
1
180
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
320
SODA - FACT BOOK(JP)
sodainc
1
40k
imagewebp()の向こう側: WebPはなぜ JPEG・PNGより軽いのか
yuzneri
0
150
Stage 3でも仕様は変わる。アプリケーション開発者のためのTC39プロセスの読み方
bicstone
1
460
AIコーディングをセッションで終わらせない: PHPライブラリ開発におけるコンテキスト承継設計
ickx
0
110
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
200
マルチプロダクトSaaSの アプリ一覧を速くする——複数プロダクトにまたがる「権限行脚」を減らすまで #techramen26conf
mktakuya
1
240
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
220
AppFunctionsの内部実装を紐解く
hiroaki404
1
120
SONY CISC-NEWS NWS-1750 + NWB-225 ハードウェアメンテとフレームバッファカラー対応 / KOF2026
tsutsui
0
150
Featured
See All Featured
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
130k
Designing for Performance
lara
612
70k
Test your architecture with Archunit
thirion
2
2.5k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
1
250
It's Worth the Effort
3n
188
30k
sira's awesome portfolio website redesign presentation
elsirapls
0
530
Fireside Chat
paigeccino
43
4.1k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
470
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
360
Ruling the World: When Life Gets Gamed
codingconduct
0
450
Un-Boring Meetings
codingconduct
0
510
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
440