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
Go で Golden File Test
Search
TOC
November 24, 2022
1.3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go で Golden File Test
Let's Go Talk #4 で LT 登壇した際の資料
https://connehito.connpass.com/event/262611/
TOC
November 24, 2022
More Decks by TOC
See All by TOC
仮説→実験→検証→学び... プロダクト開発を前に進めるためにMobius Outcome Deliveryを学び 実践していること
toc0522
3
4.1k
ファシリテーションLT ~良いファシリテーションをするために~
toc0522
0
570
もっと快適に! デプロイフロー改善への道!
toc0522
0
950
Goで学ぶ Fuzzing
toc0522
0
320
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
830
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
520
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
500
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
850
Building Adaptive Systems
keathley
44
3.2k
Ruling the World: When Life Gets Gamed
codingconduct
0
330
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
540
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
430
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Transcript
2022/11/09 Let’s Go Talk #4 TOC Go で Golden File
Test
- TOC(とっしー) - コネヒト株式会社 - バックエンドエンジニア - 主にPHP - Go
は趣味で勉強中 自己紹介
- tenntenn さんの主催する Gopher 塾に参加してきました - Testing がテーマでテスト全般の講義 - Golden
File Test も扱った - PHP でも最近使っていたので興味が沸いた LT のモチベーション
- API のレスポンスデータをファイルで保持し、比較するテスト - Snapshot Testing とも呼ばれる Golden File Test
とは 初回実行 (or -update) 目視で出力 ファイルを確認 ファイル生成 2回目以降の テスト実行 出力 比較 ファイルの データと出力 を比較
ライブラリ色々 - tenntenn/golden - シンプルで扱いやすい印象 - 最近アップデートされて更新とチェックが同時にできる - sebdah/goldie -
オプションが豊富 - 2020年からメンテされていない - gotestyourself/gotest.tools - string, []byte形式に対応
実際のコード例 - tenntenn/golden の例 - 比較やファイル生成してるのは golden.Check の部分だけ - 指定した
testdata ディレクトリ配下に {name}.golden ファイルを生成する
- 形式としては json で保存されるが、ファイルとしてはテキストファイルで 認識される - json ファイルとして認識するために工夫してるブログも - https://khigashigashi.hatenablog.com/entry/2019/04/27/15
0230 - goldie はオプションで解決できたりする - goldie.WithNameSuffix(".golden.json"), golden ファイルはテキストファイル
- json にしたとして、めっちゃ長いレスポンスを全部目視できる? - 人間誰しも見落としするよね - 外形は一緒でも中身のロジックの変化はテストできない - レスポンス構造を担保したい、とかは使えそう -
中身のロジックはユニットテストで守りたい - 何をテストしたいのか、で使い所が分かれそう Golden File Test は使い所が大事
- tenntenn/golden は json 形式以外(string, []byte, io.Reader, encoding.TextMarshaler)も対応 - txtar
形式(複数のテキストファイルをまとめたもの)とかに対して結構 使いやすくなっている - コマンドラインツールのテストでも使えそうなので使ってみたい その他所感