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
350
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
45
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
46
Strategies of Facebook LightSpeed project
elvismetaphor
0
55
Background Execution And WorkManager
elvismetaphor
2
480
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
470
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
37
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
390
o1モデルのプロンプトエンジニアリングって?
ktc_wada
0
290
rails_girls_is_my_gate_to_join_the_ruby_commuinty
maimux2x
0
200
ドメイン駆動設計を実践するために必要なもの
bikisuke
4
330
Hermes: Better Performance with Bytecode Translation (React Universe 2024)
tmikov2023
0
100
状態管理ライブラリZustandの導入から運用まで
k1tikurisu
3
470
How to Break into Reading Open Source
kaspth
2
220
大公開!iOS開発の悩みトップ5 〜iOSDC Japan 2024〜
ryunakayama
0
190
What is Parser
yui_knk
9
4.2k
Prolog入門
qnighy
4
1k
Rechartsで楽にゴリゴリにカスタマイズする!
10tera
1
170
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
510
Featured
See All Featured
Facilitating Awesome Meetings
lara
49
6k
Mobile First: as difficult as doing things right
swwweet
221
8.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
663
120k
GraphQLの誤解/rethinking-graphql
sonatard
65
9.8k
Adopting Sorbet at Scale
ufuk
73
8.9k
Designing Experiences People Love
moore
138
23k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
278
13k
How To Stay Up To Date on Web Technology
chriscoyier
786
250k
Principles of Awesome APIs and How to Build Them.
keavy
125
16k
Typedesign – Prime Four
hannesfritz
39
2.3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
8.9k
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