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
360
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
48
Strategies of Facebook LightSpeed project
elvismetaphor
0
60
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
38
Other Decks in Programming
See All in Programming
PagerDuty を軸にした On-Call 構築と運用課題の解決 / PagerDuty Japan Community Meetup 4
horimislime
1
110
Vue.js学習の振り返り
hiro_xre
2
130
hotwire_or_react
harunatsujita
8
4k
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
150
EventSourcingの理想と現実
wenas
6
2.1k
リリース8年目のサービスの1800個のERBファイルをViewComponentに移行した方法とその結果
katty0324
5
3.6k
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
830
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
100
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
130
go.mod、DockerfileやCI設定に分散しがちなGoのバージョンをまとめて管理する / Go Connect #3
arthur1
10
2.4k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
480
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
Featured
See All Featured
Designing the Hi-DPI Web
ddemaree
280
34k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
A Modern Web Designer's Workflow
chriscoyier
692
190k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Faster Mobile Websites
deanohume
304
30k
Optimizing for Happiness
mojombo
376
69k
Bash Introduction
62gerente
608
210k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
A designer walks into a library…
pauljervisheath
202
24k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.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