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
380
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
51
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
51
Strategies of Facebook LightSpeed project
elvismetaphor
0
83
Background Execution And WorkManager
elvismetaphor
2
480
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
510
Dependency Injection for testability of iOS app
elvismetaphor
1
1.4k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
290
MotionLayout Brief Introduction
elvismetaphor
1
330
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
47
Other Decks in Programming
See All in Programming
Updates on MLS on Ruby (and maybe more)
sylph01
1
170
LLMOpsのパフォーマンスを支える技術と現場で実践した改善
po3rin
8
1k
Langfuseと歩む生成AI活用推進
licux
3
320
パスタの技術
yusukebe
1
550
AHC051解法紹介
eijirou
0
640
ProxyによるWindow間RPC機構の構築
syumai
1
220
Microsoft Orleans, Daprのアクターモデルを使い効率的に開発、デプロイを行うためのSekibanの試行錯誤 / Sekiban: Exploring Efficient Development and Deployment with Microsoft Orleans and Dapr Actor Models
tomohisa
0
220
Claude Codeで実装以外の開発フロー、どこまで自動化できるか?失敗と成功
ndadayo
3
1.8k
HTMLの品質ってなんだっけ? “HTMLクライテリア”の設計と実践
unachang113
0
360
tool ディレクティブを導入してみた感想
sgash708
1
160
「手軽で便利」に潜む罠。 Popover API を WCAG 2.2の視点で安全に使うには
taitotnk
0
170
AWS発のAIエディタKiroを使ってみた
iriikeita
1
130
Featured
See All Featured
Docker and Python
trallard
45
3.5k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
RailsConf 2023
tenderlove
30
1.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
61k
We Have a Design System, Now What?
morganepeng
53
7.8k
Designing for Performance
lara
610
69k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
284
13k
4 Signs Your Business is Dying
shpigford
184
22k
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