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
android-testing-bootcamp-2
Search
Yuya Kaido
June 09, 2016
Programming
910
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
android-testing-bootcamp-2
Yuya Kaido
June 09, 2016
More Decks by Yuya Kaido
See All by Yuya Kaido
droidkaigi-2019
yuyakaido
7
4.9k
matching-dev-meetup-1
yuyakaido
1
240
minami-aoyama-night-6
yuyakaido
1
1.3k
eureka-meetup-10
yuyakaido
0
850
droidkaigi-2018
yuyakaido
4
6.2k
navitime-eureka-1
yuyakaido
0
110
droidkaigi-2017
yuyakaido
11
8.3k
retty-tech-cafe-8
yuyakaido
0
200
mti-eureka-tech-beer
yuyakaido
0
500
Other Decks in Programming
See All in Programming
自作OSでスライド発表する
uyuki234
1
3.6k
Agentic UI
manfredsteyer
PRO
0
220
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
450
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
110
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
8.6k
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
160
スマートグラスで並列バイブコーディング
hyshu
0
280
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
230
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
130
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
820
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
13
2.3k
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
640
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
Optimising Largest Contentful Paint
csswizardry
37
3.8k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
The Language of Interfaces
destraynor
162
27k
Claude Code のすすめ
schroneko
67
230k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
210
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Designing Experiences People Love
moore
143
24k
ラッコキーワード サービス紹介資料
rakko
1
3.8M
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
310
It's Worth the Effort
3n
188
29k
Transcript
Advanced Dagger for Android Android Testing Bootcamp #2 yuyakaido
ࣗݾհ • ւ౻༏ʢ͔͍Ͳ͏Ώ͏ʣ • גࣜձࣾΤϨΧ • 1ͷΠϯλʔϯΛܦͯɺ20154݄ʹ৽ଔೖࣾ • ςετ͓͡͞Μ
yuyakaido yuyakaido
גࣜձࣾΤϨΧ • ࣗࣾαʔϏεͷاըɾ։ൃɾӡӦ • ΦϯϥΠϯσʔςΟϯάαʔϏεɿ • Χοϓϧઐ༻ΞϓϦɿ • ࣾһɿ104໊ •
IAC ΤϯδχΞ 51ਓ ඇΤϯδχΞ 53ਓ
࣍ • DIͱ • جૅฤ • Ԡ༻ฤ • ·ͱΊ
DIͱ • DI = Dependency Injection • ຊޠͰɺґଘੑೖ • ґଘੑͱ
ґଘੑ • Կͱ͋ΕɺίʔυΛݟͯΈΔ • GithubRepositoryΫϥε2ͭͷΫϥεʹґଘ • ΫϥεA͕ΫϥεBʹґଘ͍ͯ͠Δ͜ͱ͕ґଘੑ public class
GithubRepository { private GithubClient githubClient = new GithubClient(); private GithubDao githubDao = new GithubDao(); }
ґଘੑ • ґଘੑ͕ϕλॻ͖ͩͱԿ͕Ϛζ͍ͷ͔ • Ϣχοτςετ͕ࠔ • ґଘઌͷΫϥε͕ਖ਼ৗʹಈ͍͍ͯΔඞཁੑ • Կͱ͔ͯ͠ґଘੑΛഉআ͍ͨ͠ •
ͱΓ͋͑ͣηολʔΛఆٛ͢Ε͍͍ͷͰʁ
ґଘੑ • ଟগґଘԼ͕͕ͬͨɺࠜຊղܾʹͳͬͯͳ͍ • Ϣχοτςετ͕ࠔ • ґଘઌͷΫϥε͕ਖ਼ৗʹಈ͍͍ͯΔඞཁੑ public class
GithubRepository { private GithubClient githubClient; private GithubDao githubDao; public void setGithubClient(GithubClient githubClient) { this.githubClient = githubClient; } public void setGithubDao(GithubDao githubDao) { this.githubDao = githubDao; } }
public class GithubRepository { private GithubClient githubClient; private GithubDao githubDao;
public GithubRepository(GithubClient client, GithubDao dao) { this.githubClient = client; this.githubDao = dao; } } public interface GithubClient { /* লུ */ } public interface GithubDao { /* লུ */ } ґଘੑ • Ϣχοτςετ͕ࠔ • GithubClientɺGithubDaoΛϞοΫ͢Ε GithubRepositoryͷϢχοτςετ͕Մೳ • ґଘΫϥε͕ਖ਼ৗʹಈ࡞͍ͯ͠Δඞཁੑ • ͱΓ͋͑ͣϞοΫͯ͠͠·͑ಈ͘
DIͱ • DI = Dependency Injection • ຊޠͰɺґଘੑೖ • DI
= ґଘΛϕλॻ͖Λආ͚ΔͨΊͷΈ
Dagger • ಥવͰ͕͢ɺDagger2ͭ͋Γ·͢ • https://github.com/square/dagger • ΦϦδφϧͬͪ͜ • https://github.com/google/dagger •
square/daggerΛϕʔεʹͯ͠Google͕ख ΛೖΕͨͷ
جૅฤ • Inject • Module • Component • جຊతͳ͍ํ
Inject • @InjectΛॻ͘ͱΠϯελϯε͕ೖ͞ΕΔ public class GithubRepository { private GithubClient
githubClient; private GithubDao githubDao; public GithubRepository(GithubClient client, GithubDao dao) { this.githubClient = client; this.githubDao = dao; } }
Inject • @InjectΛॻ͘ͱΠϯελϯε͕ೖ͞ΕΔ public class GithubRepository { private GithubClient
githubClient; private GithubDao githubDao; @Inject public GithubRepository(GithubClient client, GithubDao dao) { this.githubClient = client; this.githubDao = dao; } }
Module • ੜ͢ΔΠϯελϯεΛఆٛ͢ΔΫϥε @Module public class GithubModule {
@Provides public GithubClient provideGithubClient() { return new GithubClientImpl(); } @Provides public GithubDao provideGithubDao() { return new GithubDaoImpl(); } }
Component • ModuleͱInjectରΫϥεͷؔΛఆٛ @Component(modules = {GithubModule.class}) public interface AppComponent
{ void inject(MainActivity mainActivity); }
جຊతͳ͍ํ • DaggerAppComponentΛॳظԽ public class Genesis extends Application {
private AppComponent appComponent; public static AppComponent getAppComponent(Context context) { Genesis genesis = (Genesis) context.getApplicationContext(); return genesis.appComponent; } @Override public void onCreate() { super.onCreate(); appComponent = DaggerAppComponent.builder().build(); } }
جຊతͳ͍ํ • Inject͢Δ public class MainActivity extends Activity {
@Inject GithubRepository githubRepository; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Genesis.getAppComponent(this).inject(this); } }
Ԡ༻ฤ • Dependencies • Subcomponent
લఏ • ΞϓϦͷنʹൺྫͯ͠ɺModule૿͑Δ • Module͕૿͑ΔͱComponent͕ڊେԽ͍ͯ͘͠
Dependencies Subcomponent ͱ • ΞϓϦͷنʹൺྫͯ͠ɺModule૿͑Δ • Moduleͷཧํ๏ • Dependencies •
Subcomponent
Dependencies • ґଘ͍ͯ͠ΔModuleΛྻڍ @Component(dependencies = {GithubModule.class}) public interface AppComponent
{ void inject(MainActivity mainActivity); }
Dependencies • ґଘ͍ͯ͠ΔModuleΛྻڍ @Component(dependencies = {GithubModule.class}) public interface AppComponent
{ void inject(MainActivity mainActivity); }
Subcomponent • ComponentΛ֊Խ͢Δ @ScreenScope @Subcomponent(modules = {InstagramModule.class}) public interface
InstagramComponent { void inject(InstagramActivity instagramActivity); }
Subcomponent • ComponentΛ֊Խ͢Δ @ScreenScope @Subcomponent(modules = {InstagramModule.class}) public interface
InstagramComponent { void inject(InstagramActivity instagramActivity); }
Dependencies Subcomponent • Dependencies • ґଘ͍ͯ͠ΔModuleΛྻڍ • Subcomponent • ComponentΛ֊Խ
Dependencies Subcomponent ͷҧ͍ • Dependencies • શͯͷModule͕1ͭͷComponentʹॴଐ • Subcomponent •
Componentࣗମ͕֊Խ͞ΕɺͦΕͧΕ ͷComponent͕ModuleΛཧ ͳΔ΄Ͳɺ͔ΒΜ
Dependencies AppComponent FooModule BarModule
Subcomponent AppComponent FooComponent BarComponent
Dependencies Subcomponent • ͲͪΒΛ͏͖͔ • ن͕খ͚͞ΕɺDependencies • ͋ΔఔͷنΛఆ͢ΔͳΒɺSubcomponent • Dependenciesͩͱ1ͭͷComponent͕શͯͷґ
ଘΠϯελϯεΛཧ͢Δ͜ͱʹɺɺ
·ͱΊ • DIͱԿͳͷ͔ • ґଘੑΛϕλॻ͖͠ͳ͍ͨΊͷΈ • Daggerجૅฤ • ModuleͱComponent •
DaggerԠ༻ฤ • DependenciesͱSubcomponent
ࢀߟ • ཁ͢Δʹ DI ͬͯԿͳͷͱ͍͏ • http://nekogata.hatenablog.com/entry/ 2014/02/13/073043 • Android:
Dagger2 - Subcomponent vs. dependencies • http://yuki312.blogspot.jp/2016/02/android-dagger2- subcomponent-vs.html
Thank you :) Credit: NASA Earth Observatory/NOAA NGDC