Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
iOS版KyashにMock Frameworkを導入した話 / Introducing Ky...
Search
Hideaki Tamai
October 14, 2020
Programming
2.6k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
iOS版KyashにMock Frameworkを導入した話 / Introducing Kyash iOS Test Cases 2020
Hideaki Tamai
October 14, 2020
More Decks by Hideaki Tamai
See All by Hideaki Tamai
スタブを活用したデバッグメニュー / Debug Menu Using Stubs
tamadon
0
150
クロスグレードの実装とつらみの話
tamadon
3
1.2k
Optional(2018)年...その後
tamadon
3
1.2k
子育てエンジニアを支える技術
tamadon
3
6.5k
自作育児サポートアプリのその後
tamadon
1
2.3k
子育てエンジニアの家庭内生存戦略
tamadon
5
2.8k
ジモティー紹介
tamadon
0
1.4k
ジモティーのSEO
tamadon
0
1.6k
Other Decks in Programming
See All in Programming
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
4
400
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
4.4k
Workers Cache を知る
syumai
0
310
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
510
The Rails Doctrine Decade
koic
2
430
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
4
340
JRuby: Past, Present, and Future
headius
0
210
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
Intent as Code
shoppingjaws
6
1.1k
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.3k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
400
Featured
See All Featured
Marketing to machines
jonoalderson
1
5.8k
Design in an AI World
tapps
1
340
A Tale of Four Properties
chriscoyier
163
24k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Navigating Weather and Climate Data
rabernat
0
540
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
510
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
530
The Cult of Friendly URLs
andyhume
79
7k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Color Theory Basics | Prateek | Gurzu
gurzu
1
480
Transcript
玉井秀明 @tamadon 2020/10/14(水) iOS Test Tea Time #1 iOS版 Kyashに
Mock Frameworkを 導入した話
@tamadon @tamadon3776 ・2020/01 Kyash入社。iOSチームのテックリードをしています ・マジック:ザ・ギャザリングというカードゲームをかれこれ 20年以上プレイしています
Kyashの説明
• Visaブランドで発行されるプリペイドカードを簡単に作れる • チャージ元として以下が利用可能 ◦ 銀行口座 ◦ クレジットカード ◦ セブン銀行ATM
◦ など
Kyashのアーキテクチャについて
MVVM+Router Presentation Layer Domain Layer Data Layer API Repository UseCase
ViewModel Router ViewController UserDefaults KeyChain 画面遷移を管理
テスト方針について
ViewModelを優先的に ・ビジネスロジックがViewModelに集中している ・ロジックが肥大化しやすい→バグが起きやすい
何をテストするか?① • Observable、BehaviorRelay、Driverに期待するイベントが流れ てくるか ◦ Binding ◦ 通信状態の監視 ◦ フォーム入力時のバリデーション
◦ etc...
何をテストするか?② • 期待するmethodが呼ばれるか ◦ UseCaseの呼び出し • レスポンスは期待通りか ◦ TableView/CollectionViewのDataSource ▪
DataSourceの実装をViewModelで行っているため
func testFoo() { /// Given StubとViewModelのセットアップ /// When ViewModelのメソッド呼び出し ///
Then 値の評価 } 実装イメージ
Mock Frameworkについて
下記理由から必要と判断 • UseCaseが100以上あるので1つずつMockを書くのも大変 • UseCaseの実装が変わるたびにMockを修正するのも大変 ◦ 自動でGenerateされるようにしたい
iOS Mock Frameworkの比較 ※2020.08 時点 • 条件 ◦ Swiftで書かれている ◦
ドキュメント等の情報が豊富
GitHub上の情報 Name Size Star 開発時期 メンテナンス mockolo 716KB 242 2019.01~
それなりに活発 Cuckoo 2.28MB 1.3K 2016.10~ それなりに活発 Mockit 230KB 107 2016.05~ あまり活発ではない SwiftyMocky 17.59MB 694 2017.05~ それなりに活発
mockoloを採用することにした • 生成されたMockは最低限必要なものだけなのでシンプルで見 やすい ◦ それぞれのMethod用にHandlerが追加されるだけ • 軽量で高パフォーマンス • Class
mockはできないがiOS版Kyashは全てProtocol化してい るので問題ない
他Frameworkの検討結果① ※個人の感想です • Cuckoo/Mockit ◦ DSLなので学習コストが高い ◦ テストの書き方がFramework依存
他Frameworkの検討結果② ※個人の感想です • SwiftMocky ◦ あまり良く見ていないのですが、Given, Verify, Performとい う大文字始まりのメソッドに違和感があり見送り
mockoloの使い方
mockoloの使い方① @mockableアノテーションを付けてプロトコルを定義 /// @mockable public protocol Foo { var num:
Int { get set } func bar(arg: Float) -> String } mockoloコマンドを実行
mockoloの使い方② こんな感じのファイルが Generateされる public class FooMock: Foo { init() {}
init(num: Int = 0) { self.num = num } var numSetCallCount = 0 var underlyingNum: Int = 0 ・・・
mockoloの使い方③ GenerateされたMockクラスを呼んでXCTAsertで評価する func testMock() { let mock = FooMock(num: 5)
XCTAssertEqual(mock.numSetCallCount, 1) mock.barHandler = { arg in return String(arg) } XCTAssertEqual(mock.barCallCount, 1) }
詳しくは公式のリポジトリを参照ください https://github.com/uber/mockolo
今後の展望 • カバレッジの拡充 ◦ 導入していくつかのViewModelのテストを書いた状態 • ノウハウの共有 ◦ 試行錯誤中なので知見が溜まったらまた発表したい
Thank you 25