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
Clean Android Code for Unit Testing
Search
York Wu
July 03, 2016
Programming
0
65
Clean Android Code for Unit Testing
GDG Kaohsiung 2016/07/03
York Wu
July 03, 2016
Tweet
Share
More Decks by York Wu
See All by York Wu
Parcerler
yorkwu0318
0
75
Other Decks in Programming
See All in Programming
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
370
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
990
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
20
6.8k
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
190
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.5k
Architectural Extensions
denyspoltorak
0
270
CSC307 Lecture 06
javiergs
PRO
0
680
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
220
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
300
Patterns of Patterns
denyspoltorak
0
1.4k
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
2.4k
Featured
See All Featured
Exploring anti-patterns in Rails
aemeredith
2
250
Building AI with AI
inesmontani
PRO
1
680
Rebuilding a faster, lazier Slack
samanthasiow
85
9.4k
KATA
mclloyd
PRO
34
15k
Paper Plane (Part 1)
katiecoart
PRO
0
4k
Un-Boring Meetings
codingconduct
0
200
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Statistics for Hackers
jakevdp
799
230k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.1k
The Invisible Side of Design
smashingmag
302
51k
Transcript
Clean Android Code for Unit Testing York Wu 2016.07.03
Sample Project https://github.com/yorkwu0318/GDGK_Testing_Sample Unit testing PPT https://goo.gl/sTaFlm CI 環境建置 http://goo.gl/nAAfhF
CI PPT https://goo.gl/dSsMyU
Why Testing?
Testing Type Type Subtype Tool Unit Tests Local Unit Test
Junit Instrumented unit tests JVM
Testing Type Type Subtype Tool Integration Tests Components within your
app only Espresso Cross-app Components UI Automator
Testing Type Other Integration Test Unit Test
Demo 1
How to test it?
Model
Demo 2
None
None
None
None
UI Test!!
None
None
multi-thread
Fix it: register Idling Resource
None
How Testing
Hard to test code 1. Android Framework 2. Async Task
Write Testable Code 1. Dependency Injection 2. Base on MVP
Pattern (Clean Architecture)
Dependency Injection Demo3
None
build.gradle Ref Android Testing Codelab Android Architecture Blueprints
None
None
but unit testing..
we need better architecture • MVC • MVP • MVVM
(Databinding)
MVC C M V logic Activty LoginModel Activty, View
MVC C Activty M LoginModel V Activty, View logic Activity
and logic can’t be divided
MVP P LoginPresenter M LoginModel V Activty, View logic
MVP P LoginPresenter M LoginModel V Activty, View logic
None
None
Demo4 - MVP
None
MVVM VM LoginViewModel M LoginModel V Activty, View logic
Demo4 - MVVM
None
PreseterTest
Optimization • Data Binding • Retrofit 2 • RxJava
Retrofit 2 + RxJava Mock
RxJava mock prod
RxJava
DataBinding 1. remove findViewById( ) 2. remove view.setValue( ) 3.
simply ui logic 4. demo /ex
Testing Strategy • Mock data • Mock library
None
TDD 1. new request 2. add tests 3. red to
green practice: add new request on /ex ex: email/password regular email/password length
Summary 1. testing is used to protect code logic. 2.
testing is not used to test server API result!! 3. testing needs the testable code. 4. testable code needs good-designed code.
Q&A