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
260
非コンテナ環境において宣言的Deploymentを手軽に実現する / Declarative deployment in non-container environments
linyows
0
46
メール送信サーバの集約における透過型SMTP プロキシの定量評価 / Quantitative Evaluation of Transparent SMTP Proxy in Email Sending Server Aggregation
linyows
0
580
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
300
研究の再現性を高める 仕組みをGoでつくる / Creating a system to improve the reproducibility of research using go
linyows
1
150
奥が深いメールのシステム / The depth of Email system
linyows
4
470
IaCにおけるテスト考察 / Tests in IaC
linyows
2
520
リバースエンジニアリングとGoでSlackの認知負荷を下げる / Reducing cognitive load in Slack with Reverse-engineering and Go
linyows
2
320
透過型SMTPプロキシによる送信メールの可観測性向上 / Improved observability of outgoing emails with transparent smtp proxy
linyows
2
1k
Other Decks in Programming
See All in Programming
AWS Lambda functions with C# 用の Dev Container Template を作ってみた件
mappie_kochi
0
170
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
6k
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
120
盆栽転じて家具となる / Bonsai and Furnitures
aereal
0
1.9k
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
4
1.1k
Swiftコンパイラ超入門+async関数の仕組み
shiz
0
180
混沌とした例外処理とエラー監視に秩序をもたらす
morihirok
14
2.5k
Flatt Security XSS Challenge 解答・解説
flatt_security
0
740
ErdMap: Thinking about a map for Rails applications
makicamel
1
720
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
430
オニオンアーキテクチャを使って、 Unityと.NETでコードを共有する
soi013
0
370
CNCF Project の作者が考えている OSS の運営
utam0k
1
200
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Embracing the Ebb and Flow
colly
84
4.5k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
The Pragmatic Product Professional
lauravandoore
32
6.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
A better future with KSS
kneath
238
17k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.2k
Mobile First: as difficult as doing things right
swwweet
222
9k
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
͋Γ͕ͱ͏͍͟͝·ͨ͠