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
実践ハーネスエンジニアリング #MOSHTech
kajitack
7
6k
おれのAgentic Coding 2026/03
tsukasagr
1
140
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
1.9k
iOS機能開発のAI環境と起きた変化
ryunakayama
0
170
「効かない!」依存性注入(DI)を活用したAPI Platformのエラーハンドリング奮闘記
mkmk884
0
310
「接続」—パフォーマンスチューニングの最後の一手 〜点と点を結ぶ、その一瞬のために〜
kentaroutakeda
5
2.5k
Go_College_最終発表資料__外部公開用_.pdf
xe_pc23
0
140
Vibe하게 만드는 Flutter GenUI App With ADK , 박제창, BWAI Incheon 2026
itsmedreamwalker
0
540
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
270
PDI: Como Alavancar Sua Carreira e Seu Negócio
marcelgsantos
0
110
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
180
条件判定に名前、つけてますか? #phperkaigi #c
77web
2
980
Featured
See All Featured
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
170
Art, The Web, and Tiny UX
lynnandtonic
304
21k
The World Runs on Bad Software
bkeepers
PRO
72
12k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
The agentic SEO stack - context over prompts
schlessera
0
740
Designing for humans not robots
tammielis
254
26k
Leo the Paperboy
mayatellez
7
1.6k
The Language of Interfaces
destraynor
162
26k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Paper Plane
katiecoart
PRO
1
49k
Optimizing for Happiness
mojombo
378
71k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.8k
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