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
次世代タクシー配車サービス「MOV」におけるテスト事例紹介
Search
tokubass
July 18, 2019
Programming
1
1.3k
次世代タクシー配車サービス「MOV」におけるテスト事例紹介
- MOV紹介
- 前提環境
- テストを書く上での方針
- 並列テストのためのデータ生成
- DIできないコードと戦う
- その他tips
tokubass
July 18, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
Apache Iceberg V3 and migration to V3
tomtanaka
0
180
Metaprogramming isn't real, it can't hurt you
okuramasafumi
0
100
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
390
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
200
CSC307 Lecture 06
javiergs
PRO
0
690
CSC307 Lecture 01
javiergs
PRO
0
690
Python’s True Superpower
hynek
0
110
AI時代の認知負荷との向き合い方
optfit
0
170
並行開発のためのコードレビュー
miyukiw
1
1.3k
LLM Observabilityによる 対話型音声AIアプリケーションの安定運用
gekko0114
2
440
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.6k
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.3k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.1k
Google's AI Overviews - The New Search
badams
0
910
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
117
110k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
400
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
180
Build your cross-platform service in a week with App Engine
jlugia
234
18k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.4k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
69
Transcript
次世代タクシー配車サービス「MOV 」における テスト事例紹介 DeNA.go #2 オートモーティブ事業本部 toku_bass 1
目次 MOV 紹介 前提環境 テストを書く上での方針 並列テストのためのデータ生成 DI できないコードと戦う その他tips 2
MOV 紹介 3
MOV 紹介 2018/04 神奈川県 地域限定でリリース 2018/06 神奈川県 対象エリア拡大 2018/12 東京都
リリース 2019/07 大阪府、京都府 リリース 4
発表の前提 GAE/Go 1st MOV API サーバーで使用 test 実行方法 local でgoapp
test CircleCI chatbot E2E 5
テストを書く上での方針 注目しているtestcase 以外の暗黙のデータに依存しない テスト全体に関わる xture を使わない 並列(testing.T.Parallel )でテスト実行 6
テスト全体に関わる xture を使わない テスト実行前にマスターデータ以外をDB にload しない テストが初期 xture に依存するようになる 7
並列でテスト実行 testing.T.Parallel() をしたいがグローバルな状態をもつDB がネック user_id=1 のような固定値を書かないようにする github.com/bxcodec/faker (のv3 )がいい 8
並列テストのためのデータ生成 前述の github.com/bxcodec/faker を使用 テスト用のユーザを作りたい場合などに構造体のgotag を利用してダミ ーデータを生成する type User struct
{ Name string // ランダムな文字列を生成 Email string `faker:"email"` // email 形式で生成 } s := SomeStruct{} faker.FakeData(&s) faker:"email" のようにデフォルトで用意されているタグ以外にもプロダ クト用に自作のtag を作ることができる 9
faker のMOV での利用例 テスト用のtag をプロダクトコードに記述したくないという意見がで たため、静的解析で同等の構造体を別名で生成しgotag を付与 primary key がランダム値が偶然被らないように管理(todo)
id 採番アルゴリズム採用(go-katsubushi など) 10
DI できないコードと戦う すべてDI できればいいが、現実は厳しい。 特にtime.Now() はどこにでも現れる 11
time.Now - DI できないコードと戦う time.Now 定義をpackage 変数に保存し、ラッパー関数経由で呼び出 す テスト時にだけpackage 変数を書き換えるsetter
をビルド対象に含め る build タグを使用する 12
ラッパー package util var nowFunc func() time.Time func init() {
// setter 関数はテスト時にしか定義されない nowFunc = time.Now } func Now() time.Time { return nowFunc() } 13
setter // +build test package util import ( "sync" "time"
) var m sync.Mutex func SetNowFunc(f func() time.Time) func() { m.Lock() nowFunc = f return func() { m.Unlock() } } 14
利用例 func TestXXXX(t *testing.T) { unlock := util.SetNowFunc(func() time.Time {
return time.Date(...) // 省略 }) defer unlock() ... } 15
Client 実装をファイル単位で偽装 - DI できない コードと戦う build タグを使うことでファイル単位で偽装する大技 基本アイデア link
利用例 var gotMessageText string reset := infra.SetMock_Send(func(message domain.MailMessage) error { gotMessageText = message.TextPart return nil }) defer reset() 16
その他tips testerator pstest 17
testerator GAE 用のテストサーバーの起動には3 秒ほどかかるため、テストケー スごとに上げ下げしないためのライブラリ SpinUp 関数を呼ぶと、起動済みサーバーの情報か、起動していなけ れば改めて起動して情報を返す ins, ctx,
err := testerator.SpinUp() しかし、たまに意図せずテストサーバーが落ちる問題がおきた 18
testerator がサーバーを落とす条件 内部カウンター(Setup.counter) が0 になったとき SpinUp で+1, SpinDown で-1 Setup.total
% Setup.ResetThreshold == 0 のとき total はSpinUp のときに+1 される RestThreshold はデフォルトで1000 counter が0 にならないように中央管理 テストごとに実装者がSpinUp,SpinDown を記述していると内部カウ ンタが0 になるタイミングが発生した SpinUp するラッパー関数を用意し中央管理 19
Cloud PubSub 依存のテスト pstest が便利 Cloud PubSub の公式ライブラリのテスト方法 どうやってテストすればいいのか悩んだ場合はライブラリそのもののテ ストを確認しにいくと良い
20