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
54
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
68
Other Decks in Programming
See All in Programming
Ruby Pattern Matching
bkuhlmann
0
930
Scalable Customer Journey Orchestration (CJO)
lewuathe
0
170
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
680
GitHub Actionsで泣かないためにやっておきたい設定 / Recommended GHA settings to avoid crying
pinkumohikan
3
530
Rethinking UI building strategies @ SFI 2024
letelete
0
270
Site Reliability Engineering for GMO
pyama86
8
1k
ADRを一年運用してみた/adr_after_a_year
hanhan1978
7
2.4k
⼤規模⾔語モデルの拡張(RAG)が 終わったかも知れない件について
nearme_tech
23
15k
Hanami and htmx
bkuhlmann
0
210
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
750
GitHub Copilotのススメ
marcy731
1
200
SwiftUIで使いやすいToastの作り方 / How to build a Toast system which is easy to use in SwiftUI
lovee
3
140
Featured
See All Featured
Faster Mobile Websites
deanohume
299
30k
GraphQLとの向き合い方2022年版
quramy
32
12k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
Web development in the modern age
philhawksworth
202
10k
Six Lessons from altMBA
skipperchong
21
3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
20
1.9k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
2
3.4k
The Power of CSS Pseudo Elements
geoffreycrofte
60
5k
A Philosophy of Restraint
colly
197
16k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
227
16k
How to Ace a Technical Interview
jacobian
272
22k
Pencils Down: Stop Designing & Start Developing
hursman
117
11k
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