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
Cloud Firestore(の、スタブ)を作ってみた / Stubbing Cloud F...
Search
Hiron
December 08, 2017
Technology
920
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Cloud Firestore(の、スタブ)を作ってみた / Stubbing Cloud Firestore
Mobile Act OSAKA #2で発表したスライドです。
Hiron
December 08, 2017
More Decks by Hiron
See All by Hiron
カンファレンス動画鑑賞会のススメ / Osaka.swift #1
hironytic
0
390
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
580
Swift on Windows ファーストインプレッション / Swift on Windows First Impression
hironytic
0
740
iPadOSDC: Multiple Windows
hironytic
5
3.8k
だったら、俺が代わりにやってやる / Swift Zoomin' Challenge
hironytic
0
260
SwiftのNeverとボトム型 / Never as a Bottom Type
hironytic
2
940
4000のワーニングと戦え!これは警告だ! / 4000 Warnings
hironytic
2
920
シンボリケート / Ore-con 2018 Summer
hironytic
3
1.3k
全部iOSにしゃべらせちゃえ! / iOSDC 2018 LT
hironytic
3
2.1k
Other Decks in Technology
See All in Technology
AI時代のAPI品質を支えるガードレール / API Guardrails for API quality in the AI era
yokawasa
1
110
20260903 Tokyo Jazug Night #62 | Azure エンジニアよ、 その環境は本当にセキュアか?
olivia_0707
1
620
Tab5をRubyで動くパソコンにする
kishima
1
180
enechainの内製セルフサービスプラットフォーム
hiyosi
0
110
AIで仕事のやり方を変える
matsu7874
1
380
Sony-DroidKaigi2026
sony
1
320
データエンジニアリングワークショップ:Auto LoaderとSparkで学ぶデータパイプライン構築
databricksjapan
PRO
0
150
AI 駆動 Terraform 開発/SRE_BizReach_MIXI_2
visional_engineering_and_design
0
320
When Does a Local Qwen Start to Break
morshoto
0
180
bet_ai_day_2026_session02
agenticsec
1
980
「重なり」は迎える側がつくる ― 人もAIエージェントも歓迎するプロダクトエンジニアリング ―
go0517go
PRO
0
230
2026-09-04 SRE Tech Talk #15 怠惰なTerraform / Lazy Terraform
masasuzu
0
190
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
For a Future-Friendly Web
brad_frost
183
10k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
550
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
470
We Have a Design System, Now What?
morganepeng
55
8.3k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
3
1.2k
The Curious Case for Waylosing
cassininazir
1
490
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
A Soul's Torment
seathinner
7
3.5k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
190
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.6k
Transcript
Cloud Firestore を 作ってみた 2017/12/08 Mobile Act OSAKA #2 の、スタブ
About Me • Twitter、GitHub、Qiita、 SlideShare、Speaker Deck: ➡ hironytic • At
work: ➡ iOS (Objective-C)、 ときどき Android (Java)、 Windows UWP(C#) • At home: ➡ iOS (Swift) ひろん (一宮 浩教)
Firebase •Remote Config •App Indexing •Dynamic Links •Invites •AdWords •AdMob
•Analytics Develop Grow Earn •Cloud Messaging •Authentication •Realtime Database •Cloud Firestore (beta) •Storage •Hosting •Test Lab •Crash Reporting Oct.4, 2017 Mobile Act OSAKA #1
Cloud Firestore リアルタイムなデータ取得 サーバーとの通信も全部面倒見てくれる 使っている部分のテストどうしよう
そうだ スタブ、作ろう
スタブろう • スタブ (stub) とは、コンピュータプログラム のモジュールをテストする際、そのモジュール が呼び出す下位モジュールの代わりに用いる代 用品のこと。 引用元:Wikipedia 【スタブ】
ドキュメント • JSONライクなKey-Value • Swiftでは [String: Any] { "name": "Nobita",
"skill": "Hirune" }
コレクション • ドキュメントを含むコン テナ • コレクション内でユニー クなドキュメントIDで管 理される { "name":
"Nobita", "skill": "Hirune" } nvGvwR5 { "name": "Suneo", "skill": "Jiman" } zzD7UAv users
サブコレクション { "name": "general" } CSP36ah { "name": "random" }
CSP4CQz channels messages { "from": "AAd7UZv", "message": "何してますか?忙しいですか..." } MV5ahcO { "from": "nvGvwR5", "message": "昼寝してた" } MV5yaC0 { "from": "AAd7UZv", "message": "近くのコンビニエンスストアで..." } MV6Almn { "from": "nvGvwR5", "message": "まかせといてよ" } MV6L38V messages ...
データのリアルタイム取得 Firestore.firestore() .collection("users") .addSnapshotListener{ snapshot, error in // snapshot?.documents[0].documentID ...
String // snapshot?.documents[0].data() ... [String: Any] } コレクション
データのリアルタイム取得 Firestore.firestore() .collection("channels").document("CSP36ah") .collection("messages") .addSnapshotListener{ snapshot, error in // snapshot?.documents[0].documentID
... String // snapshot?.documents[0].data() ... [String: Any] } サブコレクション
データのリアルタイム取得 Firestore.firestore() .collection("users") .whereField("age", isGreaterThan: "18") .order(by: "age") .order(by: "name")
.addSnapshotListener{ snapshot, error in // snapshot?.documents[0].documentID ... String // snapshot?.documents[0].data() ... [String: Any] } クエリ
スタブりにくそう なので、 • すべての機能のスタブは作らない • 自分が必要なものだけ(なるべく妥協する) • Cloud Firestoreのインタフェースそのままでは やらない
どうやってスタブるか? Firestore App
DataStore どうやってスタブるか? Firestore App ある程度、操作を制限
どうやってスタブるか? DefaultDataStore Firestore StubDataStore App 通常時 テスト時 DataStore
コレクションの指定 protocol CollectionPath • コレクションを指す概念を抽象化 collection("channels") .document("CSP36ah") .collection("messages")
クエリ protocol DataStoreQuery • クエリを指定する概念を抽象化 • CollectionPathもDataStoreQuery(プロトコルを継承) collection("channels") .whereField("age", isGreaterThan:
"18") .order(by: "age") .order(by: "name")
クエリ=フィルタ+ソート collection("channels") .whereField("age", isGreaterThan: "18") .order(by: "age") [Entity] .filter(...) .sorted(...)
documentID: String data: [String: Any]
リアルタイムなデータ取得 DataStoreQueryにマッチするEntityの配列が リアルタイムに流れてくる
リアルタイムなデータ取得 DataStoreQueryにマッチするEntityの配列が リアルタイムに流れてくる RxSwiftのObservable func observeCollection(matches query: DataStoreQuery) -> Observable<[Entity]>
スタブるぞ • CollectionPathごとに Observableを保持しておく StubDataStore /channels /channels/CSP36ah/messages Observable<[Entity]> Observable<[Entity]>
/channels /channels/CSP36ah/messages Observable<[Entity]> Observable<[Entity]> スタブるぞ • DataStoreQueryに応じて、 フィルタ、ソートを行う Observableをmapで変換し て返す
StubDataStore filter(...) sorted(...) Observable<[Entity]> func observeCollection(matches query: DataStoreQuery) -> Observable<[Entity]> map
/channels /channels/CSP36ah/messages Observable<[Entity]> Observable<[Entity]> filter(...) sorted(...) Observable<[Entity]> map スタブるぞ •
元のObservableに更新が 流れれば、さっき返した Observableにも自動的に (リアルタイムに)更新 が流れる StubDataStore ✨ ✨
更新系メソッドも まるっとやれば
ほら、スタブれた ⭐ https://github.com/hironytic/CloudFirstoreStubPOC
まとめ • Cloud Firestoreのスタブを作った(スタブった) • 必要な操作にしぼってスタブりやすくした • RxSwiftのおかげでリアルタイムなデータ取得の部 分がうまいこといった •
作ったとは言ったが、使いものになるとは言って いない