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.4k
retty-tech-cafe-8
yuyakaido
0
210
mti-eureka-tech-beer
yuyakaido
0
510
Other Decks in Programming
See All in Programming
バグを直したら useEffect が消えた
colorful12
3
660
改善しないと、タスクが回らない。 “てんこ盛りポジション” を引き継いだ情シスの、入社3ヶ月の業務改善録
krm963
0
280
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
340
「人を評価する AI」の設計と実装
ryoyanara
0
220
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
530
引き算の組織 ― アウトカムとAIに全振りするために辞めたこと ― / Organization by Subtraction
hirokiyamamoto14
PRO
0
260
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
200
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
490
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
440
AIを紡ぐPMのお話
swdtkuy
0
120
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
580
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
350
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
530
The untapped power of vector embeddings
frankvandijk
2
1.8k
Heart Work Chapter 1 - Part 1
lfama
PRO
8
36k
Un-Boring Meetings
codingconduct
0
390
Ethics towards AI in product and experience design
skipperchong
2
350
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Discover your Explorer Soul
emna__ayadi
2
1.3k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
41k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.4k
WENDY [Excerpt]
tessaabrams
11
39k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
930
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
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