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
390
1
Share
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
60
Dubugging Tips and Tricks for iOS development
elvismetaphor
0
64
Strategies of Facebook LightSpeed project
elvismetaphor
0
100
Background Execution And WorkManager
elvismetaphor
2
500
作為一個跨平台的 Mobile App 開發者,從入門到放棄!?
elvismetaphor
2
540
Dependency Injection for testability of iOS app
elvismetaphor
1
1.5k
Briefly Introduction of Kotlin coroutines
elvismetaphor
1
310
MotionLayout Brief Introduction
elvismetaphor
1
350
Chapter 10. Pattern Matching with Regular Expressions
elvismetaphor
0
62
Other Decks in Programming
See All in Programming
なぜあなたのコードには「コシ」がないのか?〜AI時代に問う、最後まで美味しい設計と戦略〜 #phpconkagawa / phpconkagawa2026
shogogg
0
150
10 Tips of AWS ~Gen AI on AWS~
licux
5
540
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
140
【26新卒研修資料】TDD実装演習
dip_tech
PRO
0
170
Back to the roots of date
jinroq
0
750
AIを導入する前にやるべきこと
negima
2
340
2026年のソフトウェア開発を考える(2026/05版) / Software Engineering Scrum Fest Niigata 2026 Edition
twada
PRO
22
11k
20260514 - build with ai 2026 - build LINE Bot with Gemini CLI
line_developers_tw
PRO
0
340
Agent Skills を社内で育てる仕組み作り
jackchuka
1
1.6k
when storing skills in S3 file
watany
3
1.4k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
210
Liberating Ruby's Parser from Lexer Hacks
ydah
2
2.6k
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
120
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Color Theory Basics | Prateek | Gurzu
gurzu
0
310
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
530
KATA
mclloyd
PRO
35
15k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
WCS-LA-2024
lcolladotor
0
580
Designing Experiences People Love
moore
143
24k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
330
Thoughts on Productivity
jonyablonski
76
5.1k
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