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
180
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
650
Goトランザクション処理
matumoto
1
70
いまいちどスライスの 挙動を見直してみる
matumoto
0
380
Go1.22のリリース予定の機能を見る
matumoto
0
76
GoのUnderlying typeについて
matumoto
0
220
Typed-nilについて
matumoto
0
350
GoのType Setsという概念
matumoto
0
40
GoのRateLimit処理の実装
matumoto
0
450
Webプッシュ通知触ってみた
matumoto
0
39
Other Decks in Programming
See All in Programming
CSC307 Lecture 09
javiergs
PRO
1
850
AIコーディングの理想と現実 2026 | AI Coding: Expectations vs. Reality 2026
tomohisa
0
510
AWS Infrastructure as Code の新機能 2025 総まとめ~ SA 4人による怒涛のデモ祭り ~
konokenj
7
1k
Python’s True Superpower
hynek
0
180
AI & Enginnering
codelynx
0
140
Oxlint JS plugins
kazupon
1
1.1k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
220
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
410
個人開発は儲からない - それでも開発開始1ヶ月で300万円売り上げた方法
taishiyade
0
110
CSC307 Lecture 07
javiergs
PRO
1
560
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
220
株式会社 Sun terras カンパニーデック
sunterras
0
1.8k
Featured
See All Featured
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
220
Amusing Abliteration
ianozsvald
0
120
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.4k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
74
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
140
Mind Mapping
helmedeiros
PRO
1
100
Thoughts on Productivity
jonyablonski
75
5.1k
Designing Powerful Visuals for Engaging Learning
tmiket
0
250
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
290
We Have a Design System, Now What?
morganepeng
55
8k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Code Review Best Practice
trishagee
74
20k
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 もおもしろい