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 test -json そして testing.T.Attr / Kyoto.go #63
Search
utagawa kiki
August 31, 2025
Programming
2.8k
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
go test -json そして testing.T.Attr / Kyoto.go #63
Kyoto.go #63 オフラインLT会@マネフォ京都
https://kyotogo.connpass.com/event/363034/
utagawa kiki
August 31, 2025
More Decks by utagawa kiki
See All by utagawa kiki
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
2
1.6k
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
4.7k
tparseでgo testの出力を見やすくする
utgwkk
2
2.3k
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
3.5k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
4.6k
君たちはどうコードをレビューする (される) か / 大吉祥寺.pm
utgwkk
21
17k
Dive into gomock / Go Conference 2024
utgwkk
14
8.8k
Goでリフレクションする、その前に / Kansai.go #1
utgwkk
4
3.8k
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
7
4.4k
Other Decks in Programming
See All in Programming
Security issues being discussed on Web Platforms
petamoriken
0
980
Heart of Swift Concurrency
koher
0
910
速習iPhone Duo対応
yuukiw00w
1
660
JRuby: Past, Present, and Future
headius
0
140
標準パッケージに uuid が追加された 背景から見る Go らしい意思決定 / go_127_uuid_decision
convto
5
7.5k
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
150
Family mrubyの進捗
kishima
1
130
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.3k
iOSDC2026登壇資料.pdf
riofujimon
0
170
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
220
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
120
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
360
Featured
See All Featured
A Soul's Torment
seathinner
8
3.6k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.1k
Building Adaptive Systems
keathley
44
3.2k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
240
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
510
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
240
Mind Mapping
helmedeiros
1
360
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The Invisible Side of Design
smashingmag
301
52k
Transcript
go test -json そして testing.T.Attr id:utgwkk / @utgwkk (うたがわきき) 2025/8/31
Kyoto.go #63 オフラインLT会@マネフォ京都 #kyotogo 1
自己紹介 • うたがわきき (@utgwkk) • 株式会社はてな ◦ Webアプリケーションエンジニア • 好きなパッケージはreflect
• 最近はTypeScript書いてる 2
ここでアンケート • Goでテストを書いたことがある? • (挙手を促す) • 雰囲気わかりました 3
アジェンダ • go test -json について • testing.T.Attr について 4
アジェンダ • go test -json について • testing.T.Attr について 5
ここでアンケート • go testの-jsonオプションを知っている・ 使ったことがある? • (挙手を促す) • 雰囲気わかりました 6
go test -json • テストの出力をJSON形式で得られる • テスト結果をプログラマブルに解析・パース するのに便利 7
go test -v 8 === RUN TestDummy --- PASS: TestDummy
(0.00s) PASS ok github.com/owner/repo 0.492s
go test -json {"Time":"2025-08-25T22:14:43.946504+09:00","Action":"start","Package":"github.com/owner/repo"} {"Time":"2025-08-25T22:14:44.522307+09:00","Action":"run","Package":"github.com/owner/repo","Test":"TestDummy "} {"Time":"2025-08-25T22:14:44.522455+09:00","Action":"output","Package":"github.com/owner/repo","Test":"TestDu mmy","Output":"=== RUN TestDummy\n"}
{"Time":"2025-08-25T22:14:44.522499+09:00","Action":"output","Package":"github.com/owner/repo","Test":"TestDu mmy","Output":"--- PASS: TestDummy (0.00s)\n"} {"Time":"2025-08-25T22:14:44.522507+09:00","Action":"pass","Package":"github.com/owner/repo","Test":"TestDumm y","Elapsed":0} {"Time":"2025-08-25T22:14:44.522513+09:00","Action":"output","Package":"github.com/owner/repo","Output":"PASS \n"} {"Time":"2025-08-25T22:14:44.522989+09:00","Action":"output","Package":"github.com/owner/repo","Output":"ok \tgithub.com/owner/repo\t0.576s\n"} {"Time":"2025-08-25T22:14:44.52587+09:00","Action":"pass","Package":"github.com/owner/repo","Elapsed":0.579} 9
雰囲気を嗅ぎ取る 10 • Actionに出力の種類が入っていそう ◦ start/run/output/pass/(fail) • Actionに応じて出力されるフィールドが変わ りそう ◦
Test/Output/Elapsed
ちゃんとしたドキュメント • https://pkg.go.dev/cmd/test2json • test2jsonというコマンドでログ→JSONの変 換だけを行うこともできる ◦ cat output.log |
go tool test2json 11
go test -jsonの大まかな実装 • テストのログを1行ずつパースしている ◦ === RUN TestDummy ◦
--- PASS: TestDummy (0.00s) • cmd/internal/test2json 以下に実装がある 12
go test -jsonの活用方法 • テストの実行結果を分かりやすく表示する ◦ mfridman/tparse ◦ gotestyourself/gotestsum 13
mfridman/tparse 14 画像は mfridman/tparse のREADMEから引用
15 画像は mfridman/tparse のREADMEから引用
16 画像は gotestyourself/gotestsum のREADMEから引用
小まとめ (go test -json) • go testコマンドに-jsonオプションを渡すこ とでテストの結果をJSON形式で出力できる • go
test -jsonの出力をパースして整形する ツールがある 17
アジェンダ • go test -json について • testing.T.Attr について 18
Go 1.25 is released • 👏🎉👏 • (ここで拍手) 19
リリースノートを見る • いろいろ増えたり変わったりしてますね • そんな中、ふと目に入った新機能が…… 20
ふと目に入った新機能 >The new methods T.Attr, B.Attr, and F.Attr emit an
attribute to the test log. An attribute is an arbitrary key and value associated with a test. https://go.dev/doc/go1.25#testingpkgtesting 21
これなに • 日本語の記事がぜんぜん出てこない • リリースノートの翻訳よりも深い情報が見つ からない 22
ググったら自分のCosenseが出てくる • なかなか情報量が増えない • 助けてくれ 23
たぶん最も詳しい日本語情報 • 近頃の気になるGo testingパッケージ - Speaker Deck • CA.go#16 LT大会
の実況ログからたどって何 とかたどり着いた ◦ https://x.com/0xjj_official/status/1940000781 283074204 24
自分なりに調査してみる • Attrっていうメソッドがあることは分かった • 何もわからない ◦ 生まれた経緯は? ◦ 使い方は? •
とりあえず自分の言葉でまとめ直してみる 25
proposal探す testing: structured output for test attributes #43936 26
モチベーション • go test -json によってGoのテストの出力を プログラマブルに解析・加工できて便利 • テストのログにメタデータを含められると もっと便利になるんじゃないか
27
要するに? • テストだって構造化ログにしたい • ってこと? ◦ 誰か教えて 28
proposalのタイムライン (ざっくり) • 2021/1/27 issueが起票される • 2023/7/20 議論が進みはじめる • 2023/11/2
Russ Coxによって現行のメソッドシグネ チャが提案される ◦ t.Attr(key, value string) • 2025/4/3 proposalが受理される • 2025/8/15 Go 1.25がリリースされる 29
制約 • Attr(key, value string) • keyは空白文字を含めない • valueは改行 (CR,
LF) を含めない • 出力される順序の規定はない 30
t.Log() との棲み分け • t.Log() のほうが人間には優しい ◦ ログを出力したコードの行番号つき ◦ だいたい何でも出力できる •
テストに対するメタデータを付与したいなら t.Attr() を使う 31
メタデータ is • いくつかユースケースが示されている ◦ テストのIDを埋め込む ◦ 外部ストレージに出力したログのURLを埋める • ツールとの連携が主なユースケース?
32
なぜ Attr(key string, value any) で はないのか • slogには Any(key
string, value any) という 関数があるけれども…… ◦ だいたい何でもログ出力できる 33
なぜ Attr(key string, value any) で はないのか • valueが任意の型だと、valueを文字列化 ・JSON
encodeする必要がある ◦ 全てのテストがencoding/jsonに依存するのは微妙 ◦ 必要なときだけJSON encodeする方がいい • (このあたりの議論をかいつまんだ) 34
Attrという語彙でピンと来た方へ • log/slogにはAttrという型がある ◦ 構造化ログのパラメータを表す • log/slogが導入された辺りでproposalの議論 が進みはじめた 35
proposalのタイムライン (ざっくり) • 2021/1/27 issueが起票される • 2023/7/20 議論が進みはじめる • 2023/11/2
Russ Coxによって現行のメソッドシグネ チャが提案される ◦ t.Attr(key, value string) • 2025/4/3 proposalが受理される • 2025/8/15 Go 1.25がリリースされる 36
proposalのタイムライン (ざっくり) • 2021/1/27 issueが起票される • 2023/3/16 log/slogのproposalが受理される • 2023/7/20
議論が進みはじめる • 2023/11/2 Russ Coxによって現行のメソッドシグネ チャが提案される ◦ t.Attr(key, value string) • 2025/4/3 proposalが受理される • 2025/8/15 Go 1.25がリリースされる 37
小まとめ (testing.T.Attr) • Go 1.25 でtesting.T,B,FにAttrメソッドが追 加された ◦ テストのログに構造化されたメタデータを埋めること ができる
• 利用方法はこちらに委ねられていそう ◦ テスト結果をパースするツールでうまく使われる? 38
まとめ • proposalの議論を追うとおもしろい ◦ 慎重に議論が進められていることが分かる • なぜこういうインターフェスなのか、その答 えはproposalにあるかもしれない ◦ 謎が深まることもあるかもしれない
39
参考 • test2json command - cmd/test2json - Go Packages •
Go 1.25 is released - The Go Programming Language • Go 1.25 Release Notes - The Go Programming Language • 近頃の気になるGo testingパッケージ - Speaker Deck • testing: structured output for test attributes #43936 • log/slog: structured, leveled logging #56345 40
おまけ (AI活用事例) • NotebookLMにGitHubのissueをソースとし て渡す ◦ URLを渡すよりも、GitHub APIでissueコメントを全 取得して渡すほうが精度が高い ◦
Web UI上では省略されているコメントに大事なこと が書いてありがち 41
おまけ (AI活用事例) https://notebooklm.google.com/notebook/ c63be61a-6547-40e7-870f-8326f99b417d 42
おまけ (AI活用事例) • NotebookLMの答えが正しいかどうかは自分 の目で確かめよう ◦ 最終的には人間が英語を読む 43
おまけ (AI活用事例) • GitHub公式のMCPサーバー実装がありそう ◦ https://github.com/github/github-mcp-server ◦ これを使うと手作業でissueコメントを取ってくるの すら不要になるのでは 44