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
1
360
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
Tweet
Share
More Decks by Elvis Lin
See All by Elvis Lin
Protect Users' Privacy in iOS 14
elvismetaphor
0
46
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
48
Strategies of Facebook LightSpeed project
elvismetaphor
0
63
Background Execution And WorkManager
elvismetaphor
2
480
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
480
Dependency Injection for testability of iOS app
elvismetaphor
1
1.4k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
270
MotionLayout Brief Introduction
elvismetaphor
1
320
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
38
Other Decks in Programming
See All in Programming
return文におけるstd::moveについて
onihusube
1
1.1k
創造的活動から切り拓く新たなキャリア 好きから始めてみる夜勤オペレーターからSREへの転身
yjszk
1
130
fs2-io を試してたらバグを見つけて直した話
chencmd
0
230
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
useSyncExternalStoreを使いまくる
ssssota
6
1k
暇に任せてProxmoxコンソール 作ってみました
karugamo
2
720
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
Amazon S3 NYJavaSIG 2024-12-12
sullis
0
100
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
テストコードのガイドライン 〜作成から運用まで〜
riku929hr
3
380
これが俺の”自分戦略” プロセスを楽しんでいこう! - Developers CAREER Boost 2024
niftycorp
PRO
0
190
CSC305 Lecture 26
javiergs
PRO
0
140
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Visualization
eitanlees
146
15k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
A Tale of Four Properties
chriscoyier
157
23k
Why Our Code Smells
bkeepers
PRO
335
57k
BBQ
matthewcrist
85
9.4k
For a Future-Friendly Web
brad_frost
175
9.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Building an army of robots
kneath
302
44k
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