Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Firestoreエミュレータを使ってユニットテストを書いた話

 Firestoreエミュレータを使ってユニットテストを書いた話

Tomoyuki Ito

March 24, 2021
Tweet

Other Decks in Programming

Transcript

  1. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 Firestoreエミュレータを使って ユニットテストを書いた話 iOS Test TeaTime #2 2021/03/24(水) Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 伊藤智行 @tmyk110
  2. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 自己紹介 伊藤 智行 @tmyk110 株式会社アンドパッド SETアプリチーム所属 モバイルアプリ開発での品質向上、生産性向上に 取り組んでいます 最近はおうちコーヒーにハマっています☕ Confidential
  3. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 ちょっとだけ宣伝はいります すみません🙇 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止
  4. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 会社紹介 株式会社アンドパッド 施工管理アプリ「ANDPAD」を提 供しています ミッション: 幸せを築く人を、幸せに。 絶賛採用強化中! Confidential
  5. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 イベント紹介 アンドパッドの雰囲気やエンジニアがわかる内容になっています ぜひご視聴ください! Confidential
  6. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 改めまして本題いきます! Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止
  7. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 対象プロダクト Confidential 会社内や建築案件に関わるメンバー とメッセージのやりとりができるチャッ トアプリ REST API + RDB から Firestore にシ ステム移行中
  8. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 SET立ち上げ時の会話 Confidential 品質あげていくにはどうしたらいい ですかねー? テストカバレッジが指標として良さ そうですね。30%くらい。 いいですね、それやりましょう。 じゃあよろしくね。 はい。。。! CDO CDO 顧問
  9. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 30%に向けて Confidential レイヤー コード行数 割合 View・ViewController 6.3k 60% ViewModel 1.4k 13% Model・Logic 1.2k 11% Network 1.6k 15% カバレッジ30%の目標を達成したい。View以外ならテスト書けそう?
  10. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 Network部分のモック化 ・REST APIクライアント  → MockerでURLProtocolをモック化 Confidential ・Firestoreクライアント  → モック化する仕組みは用意されていない? 🤔? 😄
  11. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 Firestoreエミュレータを使おう! Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止
  12. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 Firestoreエミュレータについて Confidential https://firebase.google.com/docs/emulator-suite?hl=ja ローカルマシンにFirestore環境を構築できる。 Firebaseエミュレータに含まれている
  13. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 セットアップ Confidential 1. Firebase CLIのインストールと初期化 2. Firebase エミュレータの設定 3. Firebase エミュレータの起動 4. ローカルホストにアクセス
  14. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 ユニットテストで使うために Confidential
  15. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 テストの作り方 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止
  16. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 プロダクトコード例 Confidential チャットルームの一覧を取得するメソッドを例にします
  17. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 FirebaseAppのセットアップと削除 Confidential テスト毎のsetup()とteardown()でFirebaseAppの制御をします
  18. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 テストデータの書き込み Confidential 汎用的にテストデータを書き込むメソッドを用意します
  19. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 テストコード例 Confidential テストデータ書き込み → メソッドの実行 → 実行結果の確認
  20. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 (FYI) 事前にimportする方法 Confidential CLIでエミュレータ起動時に「--import」オプションで初期データの書き込 みが可能 (事前にexportしておいたもの) (使わなかった理由)  ・テストデータとテスト内容をセットで管理したかった  ・バイナリデータなのでテキストエディタで編集できない  ・テスト毎にprojectを作っているので、ちょっと難しい
  21. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 CIで実行する Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止
  22. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 Bitriseで実行した結果 Confidential BitriseのCI環境にはfirebase CLIがプリインストールされている → 追加の設定なくFirestoreエミュレータのテストが実行できました!
  23. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 困りごと😣 Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止
  24. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8. Terminating app due to uncaught exception 'com.firebase.installations', reason: 'The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized. 挙動が不安定 ・エミュレータから応答がなくT.Oしてしまうことがある ・テスト中に例外が発生してしまうことがある Confidential
  25. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 時刻が合わない Confidential ・CI環境にてテストデータとしてエミュレータに書き込んだ時刻 を、再度読み出した時の時刻がずれている ・エミュレータ側のタイムゾーン等の問題か?
  26. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 エラーのテストができない Confidential ・通信エラーなどを再現する機能がない? ・エラーハンドリングの処理をテストすることができず
  27. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 さいごに Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止
  28. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 さいごに ・Firestoreエミュレータを使ったユニットテストは  まだ安定運用できておらず ・ブログ記事などの情報もまだまだ少ないです ・同じ悩みをお持ちの方ぜひ情報交換していきましょう Confidential
  29. Copyright © 2020 Present ANDPAD Inc. This information is confidential

    and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. Proprietary & Confidential 無断転載・無断複製の禁止 ありがとうございました! Confidential Copyright © 2020 Present ANDPAD Inc. This information is confidential and was prepared by ANDPAD Inc. for the use of our client. It is not to be relied on by and 3rd party. 無断転載・無断複製の禁止