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
290
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
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
390
組込みだけじゃない! TinyGo で始める無料クラウド開発入門
otakakot
1
7
統一感のある Go コードを生成 AI の力で手にいれる
otakakot
1
3.5k
SQLBoiler がメンテナンスモードになりまして
otakakot
0
170
Wasm わからないけど Go で実装したいから入門する
otakakot
1
9.9k
cmp.Or に感動した
otakakot
3
850
無料で楽しむ Go サーバー開発のススメ
otakakot
11
3.7k
Go のテストで失敗をマークする
otakakot
1
230
Other Decks in Programming
See All in Programming
Developer Joy - The New Paradigm
hollycummins
1
410
AIと人間の共創開発!OSSで試行錯誤した開発スタイル
mae616
2
880
CSC509 Lecture 07
javiergs
PRO
0
260
オンデバイスAIとXcode
ryodeveloper
0
390
Register is more than clipboard
satorunooshie
1
390
Researchlyの開発で参考にしたデザイン
adsholoko
0
110
SidekiqでAIに商品説明を生成させてみた
akinko_0915
0
120
Introducing RemoteCompose: break your UI out of the app sandbox.
camaelon
2
460
はじめてのDSPy - 言語モデルを『プロンプト』ではなく『プログラミング』するための仕組み
masahiro_nishimi
4
18k
自動テストのアーキテクチャとその理由ー大規模ゲーム開発の場合ー
segadevtech
0
480
CSC509 Lecture 09
javiergs
PRO
0
290
AkarengaLT vol.38
hashimoto_kei
1
130
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
355
21k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
Statistics for Hackers
jakevdp
799
220k
Site-Speed That Sticks
csswizardry
13
950
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
2.9k
How to Ace a Technical Interview
jacobian
280
24k
[RailsConf 2023] Rails as a piece of cake
palkan
57
6k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
How STYLIGHT went responsive
nonsquared
100
5.9k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
34
2.3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Become a Pro
speakerdeck
PRO
29
5.6k
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. いい距離感でテストと付き合っていこうね