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
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
61
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
71
Strategies of Facebook LightSpeed project
elvismetaphor
0
110
Background Execution And WorkManager
elvismetaphor
2
500
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
550
Dependency Injection for testability of iOS app
elvismetaphor
1
1.5k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
320
MotionLayout Brief Introduction
elvismetaphor
1
360
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
66
Other Decks in Programming
See All in Programming
AIエージェントの隔離技術の徹底比較
kawayu
0
470
AIとRubyの静的型付け
ukin0k0
0
540
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
160
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
1.8k
RTSPクライアントを自作してみた話
simotin13
0
510
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
2
320
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
510
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
470
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
160
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
310
さぁV100、メモリをお食べ・・・
nilpe
0
130
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.7k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
190
Information Architects: The Missing Link in Design Systems
soysaucechin
0
960
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
250
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Building Adaptive Systems
keathley
44
3k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
360
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
400
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.5k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Amusing Abliteration
ianozsvald
1
200
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