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
net/http/httptest が推しです♡
Search
Kotaro Otaka
October 24, 2024
Programming
3
360
net/http/httptest が推しです♡
The Go gopher was designed by Renée French.
https://gotalk.connpass.com/event/331992/
Kotaro Otaka
October 24, 2024
Tweet
Share
More Decks by Kotaro Otaka
See All by Kotaro Otaka
Go で作った CLI ツールにバージョンを埋め込みたい
otakakot
0
170
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
500
組込みだけじゃない! TinyGo で始める無料クラウド開発入門
otakakot
1
93
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3.7k
SQLBoiler がメンテナンスモードになりまして
otakakot
0
290
Wasm わからないけど Go で実装したいから入門する
otakakot
1
10k
cmp.Or に感動した
otakakot
3
980
無料で楽しむ Go サーバー開発のススメ
otakakot
11
4.1k
Go のテストで失敗をマークする
otakakot
1
300
Other Decks in Programming
See All in Programming
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
180
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
180
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
5.8k
CSC307 Lecture 01
javiergs
PRO
0
680
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
560
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.1k
Apache Iceberg V3 and migration to V3
tomtanaka
0
110
Patterns of Patterns
denyspoltorak
0
1.3k
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
430
CSC307 Lecture 03
javiergs
PRO
1
480
2026年 エンジニアリング自己学習法
yumechi
0
110
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
2.4k
Featured
See All Featured
Building AI with AI
inesmontani
PRO
1
660
WENDY [Excerpt]
tessaabrams
9
36k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
The Cost Of JavaScript in 2023
addyosmani
55
9.4k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
For a Future-Friendly Web
brad_frost
181
10k
Ruling the World: When Life Gets Gamed
codingconduct
0
130
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
260
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
210
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
150
Agile that works and the tools we love
rasmusluckow
331
21k
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. いい距離感でテストと付き合っていこうね