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.3k
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
研究を支える拡張性の高い ワークフローツールの提案 / Proposal of highly expandable workflow tools to support research
linyows
0
120
非コンテナ環境において宣言的Deploymentを手軽に実現する / Declarative deployment in non-container environments
linyows
0
27
メール送信サーバの集約における透過型SMTP プロキシの定量評価 / Quantitative Evaluation of Transparent SMTP Proxy in Email Sending Server Aggregation
linyows
0
450
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
260
研究の再現性を高める 仕組みをGoでつくる / Creating a system to improve the reproducibility of research using go
linyows
1
140
奥が深いメールのシステム / The depth of Email system
linyows
4
450
IaCにおけるテスト考察 / Tests in IaC
linyows
2
480
リバースエンジニアリングとGoでSlackの認知負荷を下げる / Reducing cognitive load in Slack with Reverse-engineering and Go
linyows
2
300
透過型SMTPプロキシによる送信メールの可観測性向上 / Improved observability of outgoing emails with transparent smtp proxy
linyows
2
1k
Other Decks in Programming
See All in Programming
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
280
快速入門可觀測性
blueswen
0
400
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
290
Spatial Rendering for Apple Vision Pro
warrenm
0
120
17年周年のWebアプリケーションにTanStack Queryを導入する / Implementing TanStack Query in a 17th Anniversary Web Application
saitolume
0
250
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
200
ドメインイベント増えすぎ問題
h0r15h0
2
400
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
1
110
103 Early Hints
sugi_0000
1
250
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
110
Featured
See All Featured
Music & Morning Musume
bryan
46
6.2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
A Tale of Four Properties
chriscoyier
157
23k
We Have a Design System, Now What?
morganepeng
51
7.3k
Statistics for Hackers
jakevdp
796
220k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
The Cost Of JavaScript in 2023
addyosmani
46
7k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Site-Speed That Sticks
csswizardry
2
190
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
͋Γ͕ͱ͏͍͟͝·ͨ͠