Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
62
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
79
Strategies of Facebook LightSpeed project
elvismetaphor
0
120
Background Execution And WorkManager
elvismetaphor
2
530
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
570
Dependency Injection for testability of iOS app
elvismetaphor
1
1.5k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
330
MotionLayout Brief Introduction
elvismetaphor
1
380
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
80
Other Decks in Programming
See All in Programming
AI時代に学ぶ 好きなルール 嫌いなルール Linter編
shorty5121
0
890
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
140
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.4k
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
180
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.6k
Deep dive into the select statement (GopherCon UK)
jespino
0
170
巨大モノリシックアプリ モダン化大作戦
ktcryomm
0
140
MIZARU@SPAJAM2026 第二回予選
1901drama
0
110
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
340
Intent as Code
shoppingjaws
4
530
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
330
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
How to Talk to Developers About Accessibility
jct
2
540
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
410
Prompt Engineering for Job Search
mfonobong
0
450
Un-Boring Meetings
codingconduct
0
410
The SEO identity crisis: Don't let AI make you average
varn
0
550
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
Writing Fast Ruby
sferik
630
63k
Design in an AI World
tapps
1
310
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
320
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
490
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