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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
tokubass
July 18, 2019
Programming
1.3k
1
Share
次世代タクシー配車サービス「MOV」におけるテスト事例紹介
- MOV紹介
- 前提環境
- テストを書く上での方針
- 並列テストのためのデータ生成
- DIできないコードと戦う
- その他tips
tokubass
July 18, 2019
Other Decks in Programming
See All in Programming
Spec-driven Development: How AI Changes Everything (And Nothing)
simas
PRO
0
370
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
130
iOS機能開発のAI環境と起きた変化
ryunakayama
0
190
感情を設計する
ichimichi
5
1.6k
Terraform言語の静的解析 / static analysis of Terraform language
wata727
1
120
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.7k
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
1.1k
Agentic Elixir
whatyouhide
0
410
Road to RubyKaigi: Play Hard(ware)
makicamel
1
490
AIと共に生きる技術選定 2026
sgash708
0
110
[RubyKaigi 2026] Require Hooks
palkan
1
240
AI時代のPhpStorm最新事情 #phpcon_odawara
yusuke
0
230
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
340
58k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
140
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
310
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
How Software Deployment tools have changed in the past 20 years
geshan
0
33k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
530
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
520
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
How to Ace a Technical Interview
jacobian
281
24k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
190
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