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
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
62
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
75
Strategies of Facebook LightSpeed project
elvismetaphor
0
120
Background Execution And WorkManager
elvismetaphor
2
520
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
560
Dependency Injection for testability of iOS app
elvismetaphor
1
1.5k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
330
MotionLayout Brief Introduction
elvismetaphor
1
380
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
80
Other Decks in Programming
See All in Programming
Press start. Python's next generation.
willingc
PRO
2
110
FastAPI の並行処理モデルを完全に理解する
hoto17296
8
2.9k
typoなんかねぇよ
raspython3
0
510
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
360
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
730
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
540
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
2
990
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
370
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
220
[PyCon KR 2026] More Variants, More Diversity for AI Accelerators
achimnol
0
110
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
710
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
160
Featured
See All Featured
Test your architecture with Archunit
thirion
2
2.4k
KATA
mclloyd
PRO
35
15k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
480
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
620
AI: The stuff that nobody shows you
jnunemaker
PRO
9
940
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
220
Raft: Consensus for Rubyists
vanstee
141
7.6k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Building Applications with DynamoDB
mza
96
7.2k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
250
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