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
380
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
54
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
54
Strategies of Facebook LightSpeed project
elvismetaphor
0
90
Background Execution And WorkManager
elvismetaphor
2
490
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
520
Dependency Injection for testability of iOS app
elvismetaphor
1
1.4k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
310
MotionLayout Brief Introduction
elvismetaphor
1
330
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
50
Other Decks in Programming
See All in Programming
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
220
AtCoder Conference 2025「LLM時代のAHC」
imjk
2
640
gunshi
kazupon
1
140
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
180
Basic Architectures
denyspoltorak
0
160
[AI Engineering Summit Tokyo 2025] LLMは計画業務のゲームチェンジャーか? 最適化業務における活⽤の可能性と限界
terryu16
2
220
CSC307 Lecture 02
javiergs
PRO
1
740
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
210
これならできる!個人開発のすゝめ
tinykitten
PRO
0
140
Deno Tunnel を使ってみた話
kamekyame
0
310
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
300
生成AI時代を勝ち抜くエンジニア組織マネジメント
coconala_engineer
0
37k
Featured
See All Featured
A Tale of Four Properties
chriscoyier
162
23k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
270
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
78
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
54
Why Our Code Smells
bkeepers
PRO
340
58k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
130
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
140
BBQ
matthewcrist
89
9.9k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.3k
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