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
310
非コンテナ環境において宣言的Deploymentを手軽に実現する / Declarative deployment in non-container environments
linyows
0
75
メール送信サーバの集約における透過型SMTP プロキシの定量評価 / Quantitative Evaluation of Transparent SMTP Proxy in Email Sending Server Aggregation
linyows
0
670
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
340
研究の再現性を高める 仕組みをGoでつくる / Creating a system to improve the reproducibility of research using go
linyows
1
170
奥が深いメールのシステム / The depth of Email system
linyows
4
500
IaCにおけるテスト考察 / Tests in IaC
linyows
2
570
リバースエンジニアリングとGoでSlackの認知負荷を下げる / Reducing cognitive load in Slack with Reverse-engineering and Go
linyows
2
350
透過型SMTPプロキシによる送信メールの可観測性向上 / Improved observability of outgoing emails with transparent smtp proxy
linyows
2
1.1k
Other Decks in Programming
See All in Programming
Honoをフロントエンドで使う 3つのやり方
yusukebe
7
3.5k
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
290
From the Wild into the Clouds - Laravel Meetup Talk
neverything
0
110
Grafana Loki によるサーバログのコスト削減
mot_techtalk
1
140
SwiftUI Viewの責務分離
elmetal
PRO
2
260
Kotlinの開発でも AIをいい感じに使いたい / Making the Most of AI in Kotlin Development
kohii00
4
770
AIの力でお手軽Chrome拡張機能作り
taiseiue
0
190
Kubernetes History Inspector(KHI)を触ってみた
bells17
0
250
負債になりにくいCSSをデザイナとつくるには?
fsubal
10
2.6k
一休.com のログイン体験を支える技術 〜Web Components x Vue.js 活用事例と最適化について〜
atsumim
0
850
2025.2.14_Developers Summit 2025_登壇資料
0101unite
0
150
Domain-Driven Transformation
hschwentner
2
1.9k
Featured
See All Featured
Done Done
chrislema
182
16k
Become a Pro
speakerdeck
PRO
26
5.2k
Into the Great Unknown - MozCon
thekraken
35
1.6k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.1k
Visualization
eitanlees
146
15k
How to train your dragon (web standard)
notwaldorf
91
5.9k
Raft: Consensus for Rubyists
vanstee
137
6.8k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.5k
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
͋Γ͕ͱ͏͍͟͝·ͨ͠