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
Integration test in Go
Search
linyows
June 28, 2017
Programming
5
2.2k
Integration test in Go
Geeks Who Drink in Fukuoka -Go Go Golang Edition!- in Nulab at june 28, 2017
linyows
June 28, 2017
Tweet
Share
More Decks by linyows
See All by linyows
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
210
研究の再現性を高める 仕組みをGoでつくる / Creating a system to improve the reproducibility of research using go
linyows
1
120
奥が深いメールのシステム / The depth of Email system
linyows
3
420
IaCにおけるテスト考察 / Tests in IaC
linyows
2
440
リバースエンジニアリングとGoでSlackの認知負荷を下げる / Reducing cognitive load in Slack with Reverse-engineering and Go
linyows
2
280
透過型SMTPプロキシによる送信メールの可観測性向上 / Improved observability of outgoing emails with transparent smtp proxy
linyows
2
960
プロダクションで使うGo Pluginの利便性とパフォーマンス性 / Simplicity and Performance of Go plugin for Production
linyows
0
510
求められるソフトウェアエンジニア像とキャリア戦略 / Engineers and Career Strategies Required Now
linyows
2
480
CloudflareのCAPTCHAを使って ユーザ体験を下げず不正利用を排除する / Cloudflare's captcha case study that does not degrade ux
linyows
0
360
Other Decks in Programming
See All in Programming
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
890
Macとオーディオ再生 2024/11/02
yusukeito
0
370
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Better Code Design in PHP
afilina
PRO
0
120
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
距離関数を極める! / SESSIONS 2024
gam0022
0
280
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Adopting Sorbet at Scale
ufuk
73
9.1k
Site-Speed That Sticks
csswizardry
0
23
A better future with KSS
kneath
238
17k
We Have a Design System, Now What?
morganepeng
50
7.2k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Docker and Python
trallard
40
3.1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
What's new in Ruby 2.0
geeforr
343
31k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Transcript
5PNPIJTB0EB(.01FQBCP *OD +VOF (FFLT8IP%SJOLJO'VLVPLB (P(P(PMBOH&EJUJPO (PͰΖ͏ʂ ΠϯςάϨʔγϣϯςετ
ϓϦϯγύϧΤϯδχΞ খాԝ!MJOZPXT ٕज़෦ٕज़ج൫νʔϜ IUUQUPNPIJTBPEBDPN
ϒϩάɿIUUQUPNPIJTBPEBDPNQPTUTFBTF@NBOBHFNFOU@PG@MJOVY@TFSWFS@BENJOJTUSBUPSIUNM ࠷ۙ࡞ͬͨ044ͷ͝հ MJOVYϢʔβͷ໊લղܾΛHJUIVCͷUFBNTͰߦ͏
ৄࡉ໌ޙͷ :"1$'VLVPLBલʑࡇͰ ͓͠͠·͢ʂ ⚠શવࡊɺલࡇͷલͷ࣌ؒʹ͋ΔϖύϘඇެࣜΠϕϯτͰ͢
(PΛۀͰ͍ͬͯ·͔͢ʁ ʕ◔ϖ◔ʔ ࣸਅఏڙɿԬࢢ
(PΛۀͰ͍ͬͯ·͔͢ʁ wαʔϏεͷίΞͱ͍ͯͬͯ͠Δ wαʔϏεͷҰ෦ͱ͍ͯͬͯ͠Δ wࣾศརπʔϧͰ͍ͬͯΔ wϓϥΠϕʔτͰ͍ͬͯΔ
(Pͷςετॻ͍ͯ·͢Ͷʁ ʕ◔ϖ◔ʔ … ʕ◔ϖ◔ʔ ࣸਅఏڙɿԬࢢ
ͪΖΜॻ͍ͯ·͢ϤΥʙ ʘશһखΛ͋͛Δʗ
࠷ۙͷ෩ܠ ϧʔςΟϯά͕ແ͍͍ͤͰɺͱ͋ Δ"1*͕ػೳ͍ͯ͠ͳ͔ͬͨɻ ϧʔςΟϯάͷςετΛՃʁ 3FRVFTU%#Λελϒͯ͠"1*Λ ࣮ߦ͢ΔςετΛॻ͘ʁ ͦΕେࣄ
ͦͦ ࠷ऴతͳಈ࡞Λ୲อ͢Δ ςετ͕ͳ͔ͬͨ
ͭ·ΓɺΠϯςάϨʔγϣϯςετ ʢ"1*ͩͱ&OEUP&OEʹ͍͔ۙʣ ࣸਅఏڙɿԬࢢ
લఏ w)551 (P"1* %#Λ౷߹ͨ͠ςετ w(PͷϓϩμΫτͳͷͰ(PͰΓ͍ͨʢ wͦͯ͠γϯϓϧʹUFTUJOHύοέʔδͰ͍ྃͨ͠
ͳΔ΄Ͳʜ؆୯ʹΕ·͢Ͷ func TestFooAPI(t *testing.T) { expectedBody, _ := ioutil.ReadFile(“./testdata/foo/get_res.json”) res,
_ := http.Get(endpoint + “/foo”) gotBody, _ := ioutil.ReadALL(res.Body) res.Body.Close() if gotBody != expectedBody { t.Error(“FooAPI returns wrong body”) } }
Ϛελσʔλ ظ͢ΔϨεϙϯεͷͨΊʹ 4FFEσʔλΛςετ࣮ߦલʹ ೖΕ͓͖͍ͯͨ
5FTU.BJO͕͋Γ·ͯ͠ͶʜॳظԽͱޙॲཧ func TestMain(m *testing.M) { setup() retCode := m.Run() os.Exit(retCode)
} func setup() { db, _ := sql.Open(“postgres”, connInfo) db.Exec("DELETE FROM foo”) db.Exec("INSERT INTO bar(… defer db.Close() } func teardown() { db.Exec("TRUNCATE TABLE foo CASCAD… defer db.Close() }
5FTU.BJOQBDLBHF୯ҐͰDBMM͞ΕΔ /cmd/myapp/main.go /handlers/foo.go foo_test.go main_test.go /models/foo.go foo_test.go main_test.go /integration_test.go
5FTU.BJO ύοέʔδ͝ͱ ͔࣮̍͠ߦ͞Εͳ͍ʜ ຖճॲཧ͍ͨ͠߹ʁ
ςετͷʹࣄલࣄޙॲཧΛ͢Δ func TestFoo(t *testing.T) { defer SetupTeardown(t)() . . .
} func SetupTeardown(t *testing.T) func() { t.Log(“Setup”) return func() { t.Log(“Teardown”) } }
ීஈͷHPUFTUͰ ΠϯςάϨʔγϣϯςετ ࣮ߦ͞Εͳ͍Ͱ΄͍͠
ҾΛ͏
ͨͩ͠ɺͯ͢ͷςετʹذ͕ඞཁ var integration = flag.Bool(“integration”, false, “run integration test”) func
TestMain(m *testing.M) { flag.Parse() if *integration { setup() } retCode := m.Run() if *integration { teardown() } os.Exit(retCode) } func TestIntegration1(t *testing.T) { if !*integration { t.Skip() } . . .
Ϣχοτςετ HPUFTU ΠϯςάϨʔγϣϯςετ HPUFTUJOUFHSBUJPO ͱ͍͏͍͚͕ग़དྷΔ
͋͞ɺ͜ΕͰͲΜͲΜςετॻ͍ͯ ࣭Λ্͍͛ͯͧ͘ʂʂʂ ࣸਅఏڙɿԬࢢ
༨ஊͰ͕͢ ςετͷཻʹ όϥϯε͕͋Γ·͢ͷͰ ͝ҙ͍ͩ͘͞ 6*& (PPHMF5FTUJOH#MPH+VTU4BZ/PUP.PSF&OEUP&OE5FTUT IUUQTUFTUJOHHPPHMFCMPHDPNKVTUTBZOPUPNPSFFOEUPFOEUFTUTIUNM
·ͱΊ wΠϯςάϨʔγϣϯςετखܰʹ͔͚·͢ wҾΛ͑ϢχοτςετͱΠϯςάϨʔγϣϯςετ Λ͚࣮ͯߦͰ͖Δ wύοέʔδ͝ͱ5FTU.BJOͰςετͷࣄલࣄޙॲཧ͕Ͱ͖Δ w֤ςετ͝ͱʹࣄલࣄޙॲཧΛΓ͍ͨ߹ҰߦՃ͢ ΕՄೳ
ݕূͰͬͨίʔυͪ͜Β IUUQTHJUIVCDPNMJOZPXTHPUFTUTFUVQUFBSEPXOTBOECPY
܅ϖύϘͰಇ͔ͳ͍͔ʁ ࠷৽ͷ࠾༻ใΛνΣοΫˠ !QC@SFDSVJU
͋Γ͕ͱ͏͍͟͝·ͨ͠