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
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
60
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
64
Strategies of Facebook LightSpeed project
elvismetaphor
0
100
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
350
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
62
Other Decks in Programming
See All in Programming
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
260
「Linuxサーバー構築標準教科書」を読んでみた #ツナギメオフライン.7
akase244
0
1.4k
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
2.9k
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
480
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
160
なぜあなたのコードには「コシ」がないのか?〜AI時代に問う、最後まで美味しい設計と戦略〜 #phpconkagawa / phpconkagawa2026
shogogg
0
150
KMP × Kotlin 2.3 - How Android Got Slower While iOS Builds Improved by 47%
rio432
0
140
Liberating Ruby's Parser from Lexer Hacks
ydah
2
2.6k
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
5
1.6k
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
370
AI時代のエンジニアリングの原則 / Engineering Principles in the AI Era
haru860
0
1.1k
AI時代になぜ書くのか
mutsumix
0
270
Featured
See All Featured
Docker and Python
trallard
47
3.8k
HDC tutorial
michielstock
2
650
Site-Speed That Sticks
csswizardry
13
1.2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
160
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
110
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
290
Leo the Paperboy
mayatellez
7
1.7k
Writing Fast Ruby
sferik
630
63k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.9k
Side Projects
sachag
455
43k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
540
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