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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
660
自作OSでスライド発表する
uyuki234
1
3.6k
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
820
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
240
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
230
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
230
act1-costs.pdf
sumedhbala
0
160
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
600
Performance Engineering for Everyone
elenatanasoiu
0
250
「正の参照」と 「負の導出」で組む ハーネスエンジニアリング
cottpan
1
110
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
150
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
Raft: Consensus for Rubyists
vanstee
141
7.6k
Documentation Writing (for coders)
carmenintech
77
5.4k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.4k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
First, design no harm
axbom
PRO
2
1.2k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
120k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
280
Test your architecture with Archunit
thirion
1
2.3k
How STYLIGHT went responsive
nonsquared
100
6.2k
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