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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
73
Strategies of Facebook LightSpeed project
elvismetaphor
0
110
Background Execution And WorkManager
elvismetaphor
2
510
作為一個跨平台的 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
370
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
72
Other Decks in Programming
See All in Programming
act1-costs.pdf
sumedhbala
0
140
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.6k
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
820
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
810
Creating Composable Callables in Contemporary C++
rollbear
0
180
Lessons from Spec-Driven Development
simas
PRO
0
230
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
180
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.3k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.4k
JavaDoc 再入門
nagise
1
440
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
180
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
620
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Test your architecture with Archunit
thirion
1
2.3k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
490
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
450
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
180
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
270
Practical Orchestrator
shlominoach
191
11k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
190
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
180
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