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
Unit Testing While Using RxJava 2
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Elvis Lin
December 27, 2017
Programming
400
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Unit Testing While Using RxJava 2
Introduce how to write a unit testing while you use RxJava 2 in your program
Elvis Lin
December 27, 2017
More Decks by Elvis Lin
See All by Elvis Lin
Protect Users' Privacy in iOS 14
elvismetaphor
0
62
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
73
Strategies of Facebook LightSpeed project
elvismetaphor
0
120
Background Execution And WorkManager
elvismetaphor
2
510
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
560
Dependency Injection for testability of iOS app
elvismetaphor
1
1.5k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
330
MotionLayout Brief Introduction
elvismetaphor
1
370
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
73
Other Decks in Programming
See All in Programming
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.9k
地域 SRE コミュニティ最前線 - ホンマでっかSRE勉強会
tk3fftk
0
140
Vite+ Unified Toolchain for the Web
naokihaba
0
690
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
110
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
290
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
560
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
160
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
240
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
140
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
310
Featured
See All Featured
Site-Speed That Sticks
csswizardry
13
1.2k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.9k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
What's in a price? How to price your products and services
michaelherold
247
13k
Why Our Code Smells
bkeepers
PRO
340
58k
Optimizing for Happiness
mojombo
378
71k
Thoughts on Productivity
jonyablonski
76
5.2k
GitHub's CSS Performance
jonrohan
1033
470k
Context Engineering - Making Every Token Count
addyosmani
9
1k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
180
Transcript
如何對使⽤用 RxJava 的 程式做 Unit Test Elvis Lin 2017-12-27@Android Taipei
None
如何測試 Asynchronous Behavior 其實我想說的是
(Synchronous) Long Job Model WebClient Server 準備讀資料 資料回傳 被卡住
(Asynchronous) Long Job Model WebClient Server 準備讀資料 資料回傳 繼續執⾏行行 其他⼯工作
同步的單元測試 • doSyncCall(); • readResult(); • assertResult();
非同步的單元測試? • doAsyncCall(); • sleep(aWhile); • readResult(); • assertResult();
非同步的單元測試 — 基本技巧 • Callback • doAsyncCall(callback); • Pooling
非同步的單元測試 — Pooling doAsyncCall(); startTime = Time.now(); while (!responseReceived) {
if (Time.now() - startTime > waitLimit) throw new TestTimeoutException(); sleep (pollingInterval); } readResult(); assertResult();
在 RxJava 實作 Unit Test • 拆解 Observable 跟 Observer
• 使⽤用 TestObserver 與 TestScheduler • 使⽤用 Interface 隔離實作
拆解 Observer 跟 Observable
使⽤用 TestObserver / TestSubscriber • 範例例:https:// gist.github.com/ elvismetaphor/ 2188fd635d8e3308308bd05c59cf 63fa
使⽤用 Interface 隔離實作
重要的事情說三兩兩遍 • 拆解 Observable 跟 Observer • 使⽤用 TestObserver 與
TestScheduler • 使⽤用 Interface 隔離實作
參參考資料 • Asynchronous Behavior http://teddy-chen-tw.blogspot.tw/ 2012/12/3asynchronous-behavior.html • Testing RxJava2 https://www.infoq.com/articles/Testing-
RxJava2 • Testing asynchronous RxJava code using Mockito https://medium.com/@fabioCollini/testing- asynchronous-rxjava-code-using- mockito-8ad831a16877