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
net/http/httptest が推しです♡
Search
Kotaro Otaka
October 24, 2024
Programming
450
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
net/http/httptest が推しです♡
The Go gopher was designed by Renée French.
https://gotalk.connpass.com/event/331992/
Kotaro Otaka
October 24, 2024
More Decks by Kotaro Otaka
See All by Kotaro Otaka
Go で「見つからなかった」をどう表現するか
otakakot
0
30
actions/setup-go 完全に理解した
otakakot
1
91
Vendoring をやめたけどやめたのは正解だったのか
otakakot
0
70
t *testing.T は どこからやってくるの?
otakakot
1
1.2k
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
1.5k
Go で作った CLI ツールにバージョンを埋め込みたい
otakakot
0
260
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
660
組込みだけじゃない! TinyGo で始める無料クラウド開発入門
otakakot
1
180
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3.9k
Other Decks in Programming
See All in Programming
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
570
カツオ、ご期待ください
suneo3476
0
140
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
260
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
440
Simple Storage Service(S3) is not simple
iwatsukayura
0
120
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
370
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
420
Java 27新機能 / Java 27 new features
kishida
2
190
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
590
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
840
AWSに止められる覚悟してますか?
morizo_1984
2
500
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
290
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
340
58k
Site-Speed That Sticks
csswizardry
13
1.5k
Faster Mobile Websites
deanohume
310
32k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Code Review Best Practice
trishagee
74
20k
How to Talk to Developers About Accessibility
jct
2
560
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
440
WENDY [Excerpt]
tessaabrams
14
40k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
560
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Transcript
おーたかこーたろー @otakakot The Go gopher was designed by Renée French.
net/http/httptest が推しです♡ 2024.10.23 Go Connect #3
The Go gopher was designed by Renée French. みなさんテストはお好きですか?
The Go gopher was designed by Renée French. 私はテストが好きです。
The Go gopher was designed by Renée French. でもテストコードの保守は嫌いです。
The Go gopher was designed by Renée French. だからなるべく書きたくない。
The Go gopher was designed by Renée French. そんな私がたどり着いた(と思っている) net/http/httptest
をご紹介
The Go gopher was designed by Renée French. Kotaro Otaka
おーたかこーたろー Web Engineer 新卒入社 Hello Golang! Web Engineer 株式会社ビットキー 2020.04 2021.04 2022.11 @otakakot
The Go gopher was designed by Renée French. アジェンダ 01.
net/http/httptest との出会い 02. net/http/httptest 03. net/http/httptest (私)の使い方
The Go gopher was designed by Renée French. アジェンダ 01.
net/http/httptest との出会い 02. net/http/httptest 03. net/http/httptest (私)の使い方
The Go gopher was designed by Renée French. net/http/httptest との出会い
• zitadel/oidc にコントリビュートしたとき • 統合テストで利用 PR: https://github.com/zitadel/oidc/pull/579 Zennの記事: OSSコントリビュートの実績を解除した
The Go gopher was designed by Renée French. アジェンダ 01.
net/http/httptest との出会い 02. net/http/httptest 03. net/http/httptest (私)の使い方
The Go gopher was designed by Renée French. net/http/httptest
The Go gopher was designed by Renée French. net/http/httptest •
NewRequest / ( NewRequestWithContext 1.23 で追加 ) ◦ リクエストを生成 ◦ http.NewRequest と違い戻り値に error がない • NewRecoder() ◦ サーバーのレスポンスを記録 • NewServer() ◦ 空いているポート番号を自動で選択してサーバーを起動
The Go gopher was designed by Renée French. アジェンダ 01.
net/http/httptest との出会い 02. net/http/httptest 03. net/http/httptest (私)の使い方
The Go gopher was designed by Renée French. net/http/httptest (私)の使い方
1. NewRequest + NewRecoder を利用 ➔ 特定の Handler を対象にテスト 2. NewServer を利用 ➔ Client を用いて実際に打鍵しテスト
The Go gopher was designed by Renée French. テスト対象の API
入力 ${name} 出力 Hello, ${name}
The Go gopher was designed by Renée French. NewRequest +
NewRecoder リクエストとレスポンスを作成 Hander の実行 レスポンスの検証 これだとうまく動かない場合がある ※ ※ Zennの記事: httptest.NewRequset で Go 1.22 で追加された PathValue の値を取得する にて解説
The Go gopher was designed by Renée French. テスト対象の Handler
を登録 httptest によりサーバー起動 後片付け NewServer 準備
The Go gopher was designed by Renée French. NewServer ※
スライドの都合でエラーハンドリングは省略 リクエストを作成 クライアントによる打鍵 レスポンスの検証 ※ httptest でリクエストを作ると Client.Do() はエラーとなる
The Go gopher was designed by Renée French. いい距離感でテストと付き合っていこうね