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.5k
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
Protocol Buffersの型を超えて拡張性を得る / Beyond Protocol Buffers Types Achieving Extensibility
linyows
0
120
研究開発と実装OSSと プロダクトの好循環 / A virtuous cycle of research and development implementation OSS and products
linyows
1
580
コードジェネレーターで 効率的な開発をする / Efficient development with code generators
linyows
0
350
研究を支える拡張性の高い ワークフローツールの提案 / Proposal of highly expandable workflow tools to support research
linyows
0
490
非コンテナ環境において宣言的Deploymentを手軽に実現する / Declarative deployment in non-container environments
linyows
0
290
メール送信サーバの集約における透過型SMTP プロキシの定量評価 / Quantitative Evaluation of Transparent SMTP Proxy in Email Sending Server Aggregation
linyows
0
1k
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
520
研究の再現性を高める 仕組みをGoでつくる / Creating a system to improve the reproducibility of research using go
linyows
1
280
奥が深いメールのシステム / The depth of Email system
linyows
4
640
Other Decks in Programming
See All in Programming
Railsだからできる 例外業務に禍根を残さない 設定設計パターン
ei_ei_eiichi
0
920
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
160
CSC305 Lecture 06
javiergs
PRO
0
240
その面倒な作業、「Dart」にやらせませんか? Flutter開発者のための業務効率化
yordgenome03
1
130
10年もののAPIサーバーにおけるCI/CDの改善の奮闘
mbook
0
830
Go言語はstack overflowの夢を見るか?
logica0419
0
350
オープンソースソフトウェアへの解像度🔬
utam0k
16
3k
「ちょっと古いから」って避けてた技術書、今だからこそ読もう
mottyzzz
11
6.8k
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
32k
株式会社 Sun terras カンパニーデック
sunterras
0
320
バッチ処理を「状態の記録」から「事実の記録」へ
panda728
PRO
0
160
エンジニアインターン「Treasure」とHonoの2年、そして未来へ / Our Journey with Hono Two Years at Treasure and Beyond
carta_engineering
0
220
Featured
See All Featured
Gamification - CAS2011
davidbonilla
81
5.5k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
GitHub's CSS Performance
jonrohan
1032
470k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Designing for Performance
lara
610
69k
Visualization
eitanlees
149
16k
Side Projects
sachag
455
43k
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
͋Γ͕ͱ͏͍͟͝·ͨ͠