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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Elvis Lin
December 27, 2017
Programming
390
1
Share
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
59
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
59
Strategies of Facebook LightSpeed project
elvismetaphor
0
98
Background Execution And WorkManager
elvismetaphor
2
500
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
540
Dependency Injection for testability of iOS app
elvismetaphor
1
1.5k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
310
MotionLayout Brief Introduction
elvismetaphor
1
340
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
61
Other Decks in Programming
See All in Programming
NakouPAY説明用
annouim0
0
170
(Re)make Regexp in Ruby: Democratizing internals for the JIT
makenowjust
2
180
AI-DLC Deep Dive
yuukiyo
9
4.2k
Offline should be the norm: building local-first apps with CRDTs & Kotlin Multiplatform
renaudmathieu
0
220
ハーネスエンジニアリングにどう向き合うか 〜ルールファイルを超えて開発プロセスを設計する〜 / How to approach harness engineering
rkaga
23
13k
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
140
ドメインイベントでビジネスロジックを解きほぐす #phpcon_odawara
kajitack
3
780
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
3
350
ローカルで稼働するAI エージェントを超えて / beyond-local-ai-agents
gawa
3
280
CDK Deployのための ”反響定位”
watany
4
780
Alternatives to JPA 2026
debop
0
110
実用!Hono RPC2026
yodaka
2
230
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.4k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.7k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
320
Six Lessons from altMBA
skipperchong
29
4.2k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
260
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Abbi's Birthday
coloredviolet
2
7.1k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Balancing Empowerment & Direction
lara
6
1.1k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
160
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
sira's awesome portfolio website redesign presentation
elsirapls
0
220
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