Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go のテストで失敗をマークする
Search
Kotaro Otaka
June 07, 2024
0
110
Go のテストで失敗をマークする
https://moneyforward.connpass.com/event/313929/
での登壇資料です。
Kotaro Otaka
June 07, 2024
Tweet
Share
More Decks by Kotaro Otaka
See All by Kotaro Otaka
Wasm わからないけど Go で実装したいから入門する
otakakot
1
150
cmp.Or に感動した
otakakot
3
450
net/http/httptest が推しです♡
otakakot
3
170
無料で楽しむ Go サーバー開発のススメ
otakakot
10
3k
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
97
17k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
Agile that works and the tools we love
rasmusluckow
328
21k
The Cult of Friendly URLs
andyhume
78
6.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
5
190
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Practical Orchestrator
shlominoach
186
10k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
112
50k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.2k
Transcript
Go のテストで 失敗をマークする おーたかこーたろー / @otakakot The Go gopher was
designed by Renée French. The icon was designed by @avocadoneko. (Unofficial)Go Conference 2024 Pre Party 2024.06.07
bio Web Engineer 新卒入社 2020 年 4 月 ~ Hello
Golang ! 2021 年 4 月~ @otakakot @otakakot Web Engineer 株式会社ビットキー 2022 年 11 月 ~ Kotaro Otaka / 大高 浩太郎 The Go gopher was designed by Renée French. The icon was designed by @avocadoneko.
テストで error が発生したとき t.Error() t.Fatal() t.Fail() t.Errorf() t.Fatalf() t.FailNow()
自信を持って 失敗をマークできる!
エラー発生時に使えそうなメソッドたち ※ testing パッケージからそれっぽいメソッドを抜粋 ※ Go のバージョンは 1.22.4 を参照
使い分けるメソッドは2種類 ※ testing パッケージからそれっぽいメソッドを抜粋 ※ Go のバージョンは 1.22.4 を参照
組み合わせでできている
Log() と Logf()
Error() と Errorf() Log() Logf()
Fatal() と Fatalf() Log() Logf()
Error 系が呼び出す Fail メソッド
Fatal 系が呼び出す FailNow メソッド Reference: 【Golang】Exit, panic, Goexitの違い
エラーが発生しても、テストは継続 エラーが発生したら、テストは終了 こう使い分けよう
例えば ... Error(f) 結果と期待値の比較の失敗 Fatal(f) テストデータの準備の失敗 mock の構築の失敗
まとめ 失敗に関係しそうなメソッドを紹介 使うメソッドは2種類 失敗をマークするメソッドは組み合わせ t.Log(f) は内包 メソッドの使い分け Reference:Testing in Go:
Failing Tests Reference:testing package