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
testingを眺める
Search
matumoto
August 30, 2025
Programming
1
170
testingを眺める
会津大学Zli OB/OG LT 2025 in Tokyo 発表資料
-
https://zli.connpass.com/event/363467/
matumoto
August 30, 2025
Tweet
Share
More Decks by matumoto
See All by matumoto
sync/v2 プロポーザルの 背景と sync.Pool について
matumoto
0
570
Goトランザクション処理
matumoto
1
59
いまいちどスライスの 挙動を見直してみる
matumoto
0
360
Go1.22のリリース予定の機能を見る
matumoto
0
70
GoのUnderlying typeについて
matumoto
0
210
Typed-nilについて
matumoto
0
350
GoのType Setsという概念
matumoto
0
33
GoのRateLimit処理の実装
matumoto
0
440
Webプッシュ通知触ってみた
matumoto
0
38
Other Decks in Programming
See All in Programming
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
240
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
320
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.3k
Cap'n Webについて
yusukebe
0
160
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
510
Grafana:建立系統全知視角的捷徑
blueswen
0
250
Implementation Patterns
denyspoltorak
0
140
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
210
公共交通オープンデータ × モバイルUX 複雑な運行情報を 『直感』に変換する技術
tinykitten
PRO
0
170
re:Invent 2025 のイケてるサービスを紹介する
maroon1st
0
160
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
540
Rubyで鍛える仕組み化プロヂュース力
muryoimpl
0
230
Featured
See All Featured
How to build a perfect <img>
jonoalderson
0
4.8k
WENDY [Excerpt]
tessaabrams
9
35k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.8k
The Limits of Empathy - UXLibs8
cassininazir
1
200
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
120
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
0
26
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
A better future with KSS
kneath
240
18k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
Facilitating Awesome Meetings
lara
57
6.7k
How GitHub (no longer) Works
holman
316
140k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
51k
Transcript
testing を眺める 2025-08-30 Zli OB/OG LT
• 学籍番号:s1280136 • 所属:元会津⼤学コンピュータ理⼯学部 • 今興味のあること: • 趣味: ◦ VTuber
◦ スト6を⾒る • ひとこと: ◦ 久々にスライド作成でひりついた matumoto ⾃⼰紹介
Goのtestingパッケージ を⾒ていきます
testing
None
testing パッケージ • testing.T • testing.B • testing.TB • testing.PB
• testing.M • testing.F • いつもお世話になっております
testing.T: テスト
testing.B: ベンチマーク
testing.B: ベンチマーク • testing.T: テスト関連 • testing.B: ベンチマーク関連 • testing.TB
• testing.PB • testing.M • testing.F
testing.TB: バンジーガム testing.TB T B
testing.PB: パラレルベンチマーク
testing.M: テストのメイン関数
testing.F: ファジーテスト
testing.Short() • go test -short 指定の際に分岐できる
testing/ 配下
testing/ 配下 今回は testing/fstest を紹介
testing/fstest
こんな関数を考えてみる
こんな関数を考えてみる
ファイルシステムをいじる関数のテストは⼤変... • そもそもロジックとI/Oを分ければよいのでは? ◦ => いけそう!
None
ロジック Input Output
ロジック Input Output
これでロジックのテストは書きやすい! • ロジック部分は純粋関数なので単体テスト書くだけ! • じゃあ、Inputのときにファイル読み取れるかのテストって...?
これでロジックのテストは書きやすい! • ロジック部分は純粋関数なので単体テスト書くだけ! • じゃあ、Inputのときにファイル読み取れるかのテストって...? ファイルシステムをテストしやすくしよう!
io/fs パッケージの fs.FS インターフェース
io/fs パッケージの fs.ReadFile
os.ReadFile → fs.ReadFile に置き換える
mainではファイルシステムを渡す
テストでは fstest.MapFS を渡す
これでInputのテストは書きやすい! • Input部分は好きに単体テスト書くだけ! • じゃあ、Outputのときにファイル書き出せるかのテストって...? • io/fs.FS は基本読み取りだけ..。 t.TempDir で一時ファイルを作ろう
t.TempDir
テスト⽤の⼀時的なディレクトリを作ってくれる
ファイル書き出し後に、それを確かめる
ファイル書き出し後に、それを確かめる
まとめ • testing.T, testing.B, testing.PB, … は便利 • testing.TB はTとB、両⽅の性質を併せ持つ...♥
• testing/fstest はファイルシステムのテストに便利!
おしまい testing/iotest, testing/synctest もおもしろい