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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
60
Other Decks in Programming
See All in Programming
AI 開発合宿を通して得た学び
niftycorp
PRO
0
190
へんな働き方
yusukebe
6
2.9k
年間50登壇、単著出版、雑誌寄稿、Podcast出演、YouTube、CM、カンファレンス主催……全部やってみたので面白さ等を比較してみよう / I’ve tried them all, so let’s compare how interesting they are.
nrslib
4
650
Cyrius ーLinux非依存にコンテナをネイティブ実行する専用OSー
n4mlz
0
270
AI Assistants for YourAngular Solutions @Angular Graz, March 2026
manfredsteyer
PRO
0
140
OTP を自動で入力する裏技
megabitsenmzq
0
130
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
4.2k
飯MCP
yusukebe
0
460
モダンOBSプラグイン開発
umireon
0
190
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.5k
Ruby and LLM Ecosystem 2nd
koic
1
1.4k
ロボットのための工場に灯りは要らない
watany
12
3.3k
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Practical Orchestrator
shlominoach
191
11k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.6k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
180
Chasing Engaging Ingredients in Design
codingconduct
0
160
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Site-Speed That Sticks
csswizardry
13
1.1k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
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