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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
61
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
71
Strategies of Facebook LightSpeed project
elvismetaphor
0
110
Background Execution And WorkManager
elvismetaphor
2
500
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
550
Dependency Injection for testability of iOS app
elvismetaphor
1
1.5k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
320
MotionLayout Brief Introduction
elvismetaphor
1
360
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
66
Other Decks in Programming
See All in Programming
ふつうのFeature Flag実践入門
irof
7
3.7k
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
320
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
Modding RubyKaigi for Myself
yui_knk
0
920
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
2k
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.6k
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
180
Claspは野良GASの夢をみるか
takter00
0
180
A2UI という光を覗いてみる
satohjohn
1
130
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.4k
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
490
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
200
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.7k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
Writing Fast Ruby
sferik
630
63k
Building AI with AI
inesmontani
PRO
1
1.1k
Git: the NoSQL Database
bkeepers
PRO
432
67k
The World Runs on Bad Software
bkeepers
PRO
72
12k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
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