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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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.8k
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
18k
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
AWSに止められる覚悟してますか?
morizo_1984
1
300
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
350
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
260
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
540
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
400
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
300
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
2
300
[ハンズオン]AIへの指示だけで「五目並べ」を作ってみよう
satoshi256kbyte
1
150
JRuby: Past, Present, and Future
headius
0
190
Security issues being discussed on Web Platforms
petamoriken
0
1.2k
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
360
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
180
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
280
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Speed Design
sergeychernyshev
33
2.1k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
570
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
The Language of Interfaces
destraynor
162
27k
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