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
320
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
41
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
37
Strategies of Facebook LightSpeed project
elvismetaphor
0
51
Background Execution And WorkManager
elvismetaphor
2
470
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
420
Dependency Injection for testability of iOS app
elvismetaphor
1
1.3k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
250
MotionLayout Brief Introduction
elvismetaphor
1
310
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
36
Other Decks in Programming
See All in Programming
OpenAPIを中心に考えるAPI開発入門 / Introduction to API Development with a Focus on OpenAPI
seike460
PRO
2
120
入門 AWS Amplify Gen2 / Introduction to AWS Amplify Gen2
genkiogasawara
1
310
try! Swift Tokyo 2024のLT枠に採択されたプロポーザルを出すときに考えていたこと
ski
0
340
Folding Cheat Sheet #1
philipschwarz
PRO
0
210
スクラムチームと認知負荷 - ニフティのスクラムトーク Vol2. / NIFTY Tech Talk #18
niftycorp
PRO
1
120
スクラムガイドのスプリントレトロスペクティブを改めて読みかえしてみた / Re-reading the Sprint Retrospective Section in the Scrum Guide
mackey0225
3
330
SpringBoot+MyBatisで例外が出たときどこを見るか
syukai
0
110
ゆるい個人開発のススメ
kuroppe1819
10
940
From Spring Boot 2 to Spring Boot 3 with Java 22 and Jakarta EE
ivargrimstad
0
900
今、知っておきたい! 生成AIエージェントの世界
elith
3
340
0→1と1→10の狭間で Javaという技術選定を振り返る/Reflecting on the Decision to Choose Java Between Scaling from 0 to 1 and 1 to 10
jaguar_imo
2
370
今の SmartHR にエンジニアで入社するとどうなるの?
daisukeshinoku
5
4.6k
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
29
46k
The Power of CSS Pseudo Elements
geoffreycrofte
59
5k
Product Roadmaps are Hard
iamctodd
43
9.7k
What the flash - Photography Introduction
edds
64
11k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
Reflections from 52 weeks, 52 projects
jeffersonlam
344
19k
GraphQLの誤解/rethinking-graphql
sonatard
50
9.2k
Rebuilding a faster, lazier Slack
samanthasiow
72
8.2k
Building Adaptive Systems
keathley
30
1.8k
Code Review Best Practice
trishagee
54
15k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
18
6.9k
Side Projects
sachag
451
41k
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