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-1
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yuya Kaido
March 23, 2016
Programming
1.8k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
android-testing-bootcamp-1
Yuya Kaido
March 23, 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
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
570
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.7k
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.4k
RTSPクライアントを自作してみた話
simotin13
0
600
Creating Composable Callables in Contemporary C++
rollbear
0
100
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
390
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
130
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.4k
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
140
OSもどきOS
arkw
0
560
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.5k
Webフレームワークの ベンチマークについて
yusukebe
0
160
Featured
See All Featured
Building Applications with DynamoDB
mza
96
7.1k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
200
A Modern Web Designer's Workflow
chriscoyier
698
190k
Paper Plane
katiecoart
PRO
1
51k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Building AI with AI
inesmontani
PRO
1
1.1k
Six Lessons from altMBA
skipperchong
29
4.3k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
We Are The Robots
honzajavorek
0
240
Raft: Consensus for Rubyists
vanstee
141
7.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
Designing for Timeless Needs
cassininazir
1
250
Transcript
ςελϒϧͳઃܭΛ ໝͯ͠Έͨ Android Testing Bootcamp #1 yuyakaido
ࣗݾհ • ւ౻༏ʢ͔͍Ͳ͏Ώ͏ʣ • גࣜձࣾΤϨΧ • ςετॻ͚ॻ͚͓͡͞Μ • Android
yuyakaido yuyakaido
גࣜձࣾΤϨΧ • ࣗࣾαʔϏεͷاըɾ։ൃɾӡӦ • ΦϯϥΠϯσʔςΟϯάαʔϏεɿ • Χοϓϧઐ༻ΞϓϦɿ • ࣾһɿ100໊ •
IAC ΤϯδχΞ 60 ඇΤϯδχΞ 40
࣍ • ಈػ • શମํ • શମઃܭ • DaggerͱRxJava •
ςετίʔυ • ·ͱΊ
࣍ • ಈػ • શମํ • શମઃܭ • DaggerͱRxJava •
ςετίʔυ • ·ͱΊ
ಈػ • େنΞϓϦͷϝϯςφϯε͕ਏ͍ • ςετΛॻ͖͍͚ͨͲɺઃܭ͕ͪΌΜͱͯ͠ ͳ͍ͱςετ͕ॻ͖ʹ͍͘ • ςετ͕ॻ͖͍͢ઃܭΛໝͯ͠Έͨ
࣍ • ಈػ • શମํ • શମઃܭ • DaggerͱRxJava •
ςετίʔυ • ·ͱΊ
શମํ • ܧଓతΠϯςάϨʔγϣϯ • ςετͷ࣮ߦΛॏࢹ • ग़དྷΔ͚ͩJUnit/RobolectircͰςετ͢Δ • JUnit/Robolectricͩͱςετ͕͍͠ͱ͜ Ζ͚ͩEspressoͰςετ͢Δ
࣍ • ಈػ • શମํ • શମઃܭ • DaggerͱRxJava •
ςετίʔυ • ·ͱΊ
શମઃܭ Repository UseCase Presenter View Dao Client Database Server
Presentation Domain Infrastructure
Presentation • Ͳ͏දࣔ͢Δ͔Λهड़ • MVPϞυΩ • PresenterPure Java (ContextҎ֎) •
PresenterJUnit/RobolectricͰςετ • ViewEspressoͰςετ(Robolectricซ༻)
Domain • ԿΛ࣮ݱ͢Δ͔Λهड़ • Pure Java (ContextҎ֎) • JUnit/RobolectricͰςετ
Infrastructure • Ͳ͏࣮ͬͯݱ͢Δ͔Λهड़ • DB • API • Pure Java
(ContextҎ֎) • JUnit/RobolectricͰςετ
࣍ • ಈػ • શମํ • શମઃܭ • DaggerͱRxJava •
ςετίʔυ • ·ͱΊ
Dagger • https://github.com/google/dagger • ຊ൪ͱςετͰΠϯελϯεͷࠩ͠ସ͑ PresentationModule DomainModule AppComponent InfraModule
BarModule FooModule BazModule
RxJava • https://github.com/ReactiveX/RxJava • ֤ΛObservableͰ࿈݁ • ࣮ߦ࣌ʹεϨου͕ࣗ༝ʹઃఆग़དྷΔͨΊɺ ςετ͕ॻ͖͘͢ͳΔ
࣍ • ಈػ • શମํ • શମઃܭ • DaggerͱRxJava •
ςετίʔυ • ·ͱΊ
ςετίʔυ • Client • Presenter • ৄͪ͘͜͠Β • https://github.com/yuyakaido/android-genesis
Client • GithubͷAPIΛͬͨαϯϓϧ • ొਓ • GithubClient 㲗 GithubClientTest •
GithubInfraModule 㲗 GithubInfraTestModule
GithubClient public class GithubClient { private GithubService githubService;
@Inject public GithubClient(GithubService service) { this.githubService = service; } public Observable<List<GithubContributor>> getGithubContributors(String owner, String repo) { return CommonClient.retry(githubService.getGithubContributors(owner, repo)); } public Observable<List<GithubContributor>> getGithubContributors() { return getGithubContributors("konifar", "droidkaigi2016"); } public interface GithubService { @GET("/repos/{owner}/{repo}/contributors") Observable<List<GithubContributor>> getGithubContributors( @Path("owner") String owner, @Path("repo") String repo); } } ΞϓϦ
GithubClient public class GithubClient { private GithubService githubService;
@Inject public GithubClient(GithubService service) { this.githubService = service; } public Observable<List<GithubContributor>> getGithubContributors(String owner, String repo) { return CommonClient.retry(githubService.getGithubContributors(owner, repo)); } public Observable<List<GithubContributor>> getGithubContributors() { return getGithubContributors("konifar", "droidkaigi2016"); } public interface GithubService { @GET("/repos/{owner}/{repo}/contributors") Observable<List<GithubContributor>> getGithubContributors( @Path("owner") String owner, @Path("repo") String repo); } } ΞϓϦ
GithubClient public class GithubClient { private GithubService githubService;
@Inject public GithubClient(GithubService service) { this.githubService = service; } public Observable<List<GithubContributor>> getGithubContributors(String owner, String repo) { return CommonClient.retry(githubService.getGithubContributors(owner, repo)); } public Observable<List<GithubContributor>> getGithubContributors() { return getGithubContributors("konifar", "droidkaigi2016"); } public interface GithubService { @GET("/repos/{owner}/{repo}/contributors") Observable<List<GithubContributor>> getGithubContributors( @Path("owner") String owner, @Path("repo") String repo); } } ΞϓϦ
GithubClient public class GithubClient { private GithubService githubService;
@Inject public GithubClient(GithubService service) { this.githubService = service; } public Observable<List<GithubContributor>> getGithubContributors(String owner, String repo) { return CommonClient.retry(githubService.getGithubContributors(owner, repo)); } public Observable<List<GithubContributor>> getGithubContributors() { return getGithubContributors("konifar", "droidkaigi2016"); } public interface GithubService { @GET("/repos/{owner}/{repo}/contributors") Observable<List<GithubContributor>> getGithubContributors( @Path("owner") String owner, @Path("repo") String repo); } } ΞϓϦ
GithubInfraModule @Module public class GithubInfraModule { @Provides @Singleton public
GithubClient.GithubService provideGithubService() { return ApiClientGenerator.generate( GithubClient.GithubService.class, "https://api.github.com"); } } ςετ
GithubClientTest public class GithubClientTest extends InfraTest { @Test public
void getGithubContributorsTest() throws Exception { File file = new File("src/test/assets/json/github_contributors.json"); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(ResponseUtil.createMockResponse(file)); mockWebServer.start(); GithubInfraTestModule githubInfraTestModule = new GithubInfraTestModule(); GithubClient githubClient = new GithubClient( githubInfraTestModule.provideGithubService(mockWebServer)); TestSubscriber<List<GithubContributor>> testSubscriber = new TestSubscriber<>(); githubClient.getGithubContributors().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); List<GithubContributor> githubContributors = testSubscriber.getOnNextEvents().get(0); assertThat(githubContributors.size(), is(1)); } } ςετ
GithubClientTest public class GithubClientTest extends InfraTest { @Test public
void getGithubContributorsTest() throws Exception { File file = new File("src/test/assets/json/github_contributors.json"); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(ResponseUtil.createMockResponse(file)); mockWebServer.start(); GithubInfraTestModule githubInfraTestModule = new GithubInfraTestModule(); GithubClient githubClient = new GithubClient( githubInfraTestModule.provideGithubService(mockWebServer)); TestSubscriber<List<GithubContributor>> testSubscriber = new TestSubscriber<>(); githubClient.getGithubContributors().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); List<GithubContributor> githubContributors = testSubscriber.getOnNextEvents().get(0); assertThat(githubContributors.size(), is(1)); } } ςετ
GithubInfraTestModule @Module public class GithubInfraTestModule { @Provides public GithubClient.GithubService
provideGithubService(MockWebServer mockWebServer) { return ApiClientGenerator.generate( GithubClient.GithubService.class, mockWebServer.url("").toString()); } } ςετ
GithubClientTest public class GithubClientTest extends InfraTest { @Test public
void getGithubContributorsTest() throws Exception { File file = new File("src/test/assets/json/github_contributors.json"); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(ResponseUtil.createMockResponse(file)); mockWebServer.start(); GithubInfraTestModule githubInfraTestModule = new GithubInfraTestModule(); GithubClient githubClient = new GithubClient( githubInfraTestModule.provideGithubService(mockWebServer)); TestSubscriber<List<GithubContributor>> testSubscriber = new TestSubscriber<>(); githubClient.getGithubContributors().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); List<GithubContributor> githubContributors = testSubscriber.getOnNextEvents().get(0); assertThat(githubContributors.size(), is(1)); } } ςετ
GithubClientTest public class GithubClientTest extends InfraTest { @Test public
void getGithubContributorsTest() throws Exception { File file = new File("src/test/assets/json/github_contributors.json"); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(ResponseUtil.createMockResponse(file)); mockWebServer.start(); GithubInfraTestModule githubInfraTestModule = new GithubInfraTestModule(); GithubClient githubClient = new GithubClient( githubInfraTestModule.provideGithubService(mockWebServer)); TestSubscriber<List<GithubContributor>> testSubscriber = new TestSubscriber<>(); githubClient.getGithubContributors().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); List<GithubContributor> githubContributors = testSubscriber.getOnNextEvents().get(0); assertThat(githubContributors.size(), is(1)); } } ςετ
GithubClientTest public class GithubClientTest extends InfraTest { @Test public
void getGithubContributorsTest() throws Exception { File file = new File("src/test/assets/json/github_contributors.json"); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(ResponseUtil.createMockResponse(file)); mockWebServer.start(); GithubInfraTestModule githubInfraTestModule = new GithubInfraTestModule(); GithubClient githubClient = new GithubClient( githubInfraTestModule.provideGithubService(mockWebServer)); TestSubscriber<List<GithubContributor>> testSubscriber = new TestSubscriber<>(); githubClient.getGithubContributors().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); List<GithubContributor> githubContributors = testSubscriber.getOnNextEvents().get(0); assertThat(githubContributors.size(), is(1)); } } ςετ
GithubClientTest public class GithubClientTest extends InfraTest { @Test public
void getGithubContributorsTest() throws Exception { File file = new File("src/test/assets/json/github_contributors.json"); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(ResponseUtil.createMockResponse(file)); mockWebServer.start(); GithubInfraTestModule githubInfraTestModule = new GithubInfraTestModule(); GithubClient githubClient = new GithubClient( githubInfraTestModule.provideGithubService(mockWebServer)); TestSubscriber<List<GithubContributor>> testSubscriber = new TestSubscriber<>(); githubClient.getGithubContributors().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); List<GithubContributor> githubContributors = testSubscriber.getOnNextEvents().get(0); assertThat(githubContributors.size(), is(1)); } } ςετ
GithubClientTest public class GithubClientTest extends InfraTest { @Test public
void getGithubContributorsTest() throws Exception { File file = new File("src/test/assets/json/github_contributors.json"); MockWebServer mockWebServer = new MockWebServer(); mockWebServer.enqueue(ResponseUtil.createMockResponse(file)); mockWebServer.start(); GithubInfraTestModule githubInfraTestModule = new GithubInfraTestModule(); GithubClient githubClient = new GithubClient( githubInfraTestModule.provideGithubService(mockWebServer)); TestSubscriber<List<GithubContributor>> testSubscriber = new TestSubscriber<>(); githubClient.getGithubContributors().subscribe(testSubscriber); testSubscriber.assertNoErrors(); testSubscriber.assertCompleted(); List<GithubContributor> githubContributors = testSubscriber.getOnNextEvents().get(0); assertThat(githubContributors.size(), is(1)); } } ςετ
Clientͷςετ • square/okhttp/mockwebserver͕ศར • DaggerΛͬͯϞοΫαʔόʔͷࠩ͠ସ͑ • JUnit/RobolectricͰߴʹςετՄೳ
Presenter • Clientͱಉ༷ʹGithubͷAPIΛͬͨαϯϓϧ • ొਓ • GithubPresenter 㲗 GithubPresenterTest
GithubPresenter public class GithubPresenter { @Inject Scheduler scheduler;
private GithubView githubView; private GithubUseCase githubUseCase; public GithubPresenter(Context context, GithubView githubView, GithubUseCase githubUseCase) { Genesis.getGenesisComponent(context).inject(this); this.githubView = githubView; this.githubUseCase = githubUseCase; } ʢதུʣ } ΞϓϦ
GithubPresenter public class GithubPresenter { public void onCreate() {
githubView.initViews(); githubView.showProgressBar(); githubView.refresh(); } public void onItemClick(GithubContributor githubContributor) { githubView.startWebViewActivity(githubContributor); } ʢதུʣ } ΞϓϦ
GithubPresenter public class GithubPresenter { public void refresh() {
githubUseCase.getGithubContributors() .subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<List<GithubContributor>>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { } @Override public void onNext(List<GithubContributor> githubContributors) { githubView.setGithubContributors(githubContributors); githubView.hideProgressBar(); } }); } ʢதུʣ } ΞϓϦ
GithubPresenterTest public class GithubPresenterTest extends PresentationTest { private GithubView
githubView; private GithubUseCase githubUseCase; private GithubPresenter githubPresenter; @Override public void setUp() { super.setUp(); githubView = mock(GithubView.class); githubUseCase = mock(GithubUseCase.class); githubPresenter = new GithubPresenter(getContext(), githubView, githubUseCase); } ʢதུʣ } ςετ
GithubPresenterTest public class GithubPresenter { public void onCreate() {
githubView.initViews(); githubView.showProgressBar(); githubView.refresh(); } } public class GithubPresenterTest extends PresentationTest { @Test public void onCreateTest() { githubPresenter.onCreate(); verify(githubView, times(1)).initViews(); verify(githubView, times(1)).showProgressBar(); verify(githubView, times(1)).refresh(); } } ςετ
GithubPresenterTest public class GithubPresenter { public void onCreate() {
githubView.initViews(); githubView.showProgressBar(); githubView.refresh(); } } public class GithubPresenterTest extends PresentationTest { @Test public void onCreateTest() { githubPresenter.onCreate(); verify(githubView, times(1)).initViews(); verify(githubView, times(1)).showProgressBar(); verify(githubView, times(1)).refresh(); } } ςετ
GithubPresenterTest public class GithubPresenter { public void onCreate() {
githubView.initViews(); githubView.showProgressBar(); githubView.refresh(); } } public class GithubPresenterTest extends PresentationTest { @Test public void onCreateTest() { githubPresenter.onCreate(); verify(githubView, times(1)).initViews(); verify(githubView, times(1)).showProgressBar(); verify(githubView, times(1)).refresh(); } } ςετ
GithubPresenterTest public class GithubPresenter { public void onCreate() {
githubView.initViews(); githubView.showProgressBar(); githubView.refresh(); } } public class GithubPresenterTest extends PresentationTest { @Test public void onCreateTest() { githubPresenter.onCreate(); verify(githubView, times(1)).initViews(); verify(githubView, times(1)).showProgressBar(); verify(githubView, times(1)).refresh(); } } ςετ
GithubPresenterTest public class GithubPresenter { public void onCreate() {
githubView.initViews(); githubView.showProgressBar(); githubView.refresh(); } } public class GithubPresenterTest extends PresentationTest { @Test public void onCreateTest() { githubPresenter.onCreate(); verify(githubView, times(1)).initViews(); verify(githubView, times(1)).showProgressBar(); verify(githubView, times(1)).refresh(); } } ςετ
GithubPresenterTest public class GithubPresenter { public void refresh() { githubUseCase.getGithubContributors()
.subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<GithubContributor>>() { @Override public void call(List<GithubContributor> githubContributors) { githubView.setGithubContributors(githubContributors); githubView.hideProgressBar(); } }); } } public class GithubPresenterTest extends PresentationTest { @Test public void refreshTest() { Observable<List<GithubContributor>> observable = Observable.create( new Observable.OnSubscribe<List<GithubContributor>>() { @Override public void call(Subscriber<? super List<GithubContributor>> subscriber) { subscriber.onNext(new ArrayList<GithubContributor>()); subscriber.onCompleted(); } } ); when(githubUseCase.getGithubContributors()).thenReturn(observable); githubPresenter.refresh(); verify(githubView, times(1)).setGithubContributors(new ArrayList<GithubContributor>()); verify(githubView, times(1)).hideProgressBar(); } } ςετ
GithubPresenterTest public class GithubPresenter { public void refresh() { githubUseCase.getGithubContributors()
.subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<GithubContributor>>() { @Override public void call(List<GithubContributor> githubContributors) { githubView.setGithubContributors(githubContributors); githubView.hideProgressBar(); } }); } } public class GithubPresenterTest extends PresentationTest { @Test public void refreshTest() { Observable<List<GithubContributor>> observable = Observable.create( new Observable.OnSubscribe<List<GithubContributor>>() { @Override public void call(Subscriber<? super List<GithubContributor>> subscriber) { subscriber.onNext(new ArrayList<GithubContributor>()); subscriber.onCompleted(); } } ); when(githubUseCase.getGithubContributors()).thenReturn(observable); githubPresenter.refresh(); verify(githubView, times(1)).setGithubContributors(new ArrayList<GithubContributor>()); verify(githubView, times(1)).hideProgressBar(); } } ςετ
GithubPresenterTest public class GithubPresenter { public void refresh() { githubUseCase.getGithubContributors()
.subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<GithubContributor>>() { @Override public void call(List<GithubContributor> githubContributors) { githubView.setGithubContributors(githubContributors); githubView.hideProgressBar(); } }); } } public class GithubPresenterTest extends PresentationTest { @Test public void refreshTest() { Observable<List<GithubContributor>> observable = Observable.create( new Observable.OnSubscribe<List<GithubContributor>>() { @Override public void call(Subscriber<? super List<GithubContributor>> subscriber) { subscriber.onNext(new ArrayList<GithubContributor>()); subscriber.onCompleted(); } } ); when(githubUseCase.getGithubContributors()).thenReturn(observable); githubPresenter.refresh(); verify(githubView, times(1)).setGithubContributors(new ArrayList<GithubContributor>()); verify(githubView, times(1)).hideProgressBar(); } } ςετ
GithubPresenterTest public class GithubPresenter { public void refresh() { githubUseCase.getGithubContributors()
.subscribeOn(scheduler) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<GithubContributor>>() { @Override public void call(List<GithubContributor> githubContributors) { githubView.setGithubContributors(githubContributors); githubView.hideProgressBar(); } }); } } public class GithubPresenterTest extends PresentationTest { @Test public void refreshTest() { Observable<List<GithubContributor>> observable = Observable.create( new Observable.OnSubscribe<List<GithubContributor>>() { @Override public void call(Subscriber<? super List<GithubContributor>> subscriber) { subscriber.onNext(new ArrayList<GithubContributor>()); subscriber.onCompleted(); } } ); when(githubUseCase.getGithubContributors()).thenReturn(observable); githubPresenter.refresh(); verify(githubView, times(1)).setGithubContributors(new ArrayList<GithubContributor>()); verify(githubView, times(1)).hideProgressBar(); } } ςετ
GithubPresenterTest public class GithubPresenter { public void onItemClick(GithubContributor githubContributor)
{ githubView.startWebViewActivity(githubContributor); } } public class GithubPresenterTest extends PresentationTest { @Test public void onItemClickTest() { githubPresenter.onItemClick(null); verify(githubView, times(1)).startWebViewActivity(null); } } ςετ
GithubPresenterTest public class GithubPresenter { public void onItemClick(GithubContributor githubContributor)
{ githubView.startWebViewActivity(githubContributor); } } public class GithubPresenterTest extends PresentationTest { @Test public void onItemClickTest() { githubPresenter.onItemClick(null); verify(githubView, times(1)).startWebViewActivity(null); } } ςετ
GithubPresenterTest public class GithubPresenter { public void onItemClick(GithubContributor githubContributor)
{ githubView.startWebViewActivity(githubContributor); } } public class GithubPresenterTest extends PresentationTest { @Test public void onItemClickTest() { githubPresenter.onItemClick(null); verify(githubView, times(1)).startWebViewActivity(null); } } ςετ
Presenterͷςετ • நԽ͞ΕͨUseCaseͱView • ͦΕΒʹର͢ΔΠϯλϥΫγϣϯ͕దʹߦ ΘΕ͍ͯΔ͔Λςετ • JUnit/RobolectricͰߴʹςετՄೳ
࣍ • ಈػ • શମํ • શମઃܭ • DaggerͱRxJava •
ςετίʔυ • ·ͱΊ
·ͱΊ • PresentationɿͲ͏දࣔ͢Δ͔ • DomainɿԿΛ࣮ݱ͢Δ͔ • InfrastructureɿͲ͏࣮ͬͯݱ͢Δ͔ • DIΛͬͯຊ൪ͱςετͰΠϯελϯεΛΓସ͑Δ •
RxJavaΛ࣮ͬͯߦεϨουͷΓସ͑
·ͱΊ • ϝϦοτ • ֤ͷׂͱґଘؔΛཧͨ͜͠ͱͰςελϒϧͳઃܭʹ • AndroidͷґଘΛ࠷খݶʹͨ͜͠ͱͰߴͳςετՄೳʹ • σϝϦοτ •
Ϋϥε͕ଟ͍ • νʔϜ։ൃͷ߹͋ΔఔͷυΩϡϝϯτ͕ඞਢ
ΤϯδχΞ ઈࢍ࠾༻தʂ ฐࣾ$%0 ʢνʔϑɾυοάɾΦϑΟαʔʣ ͝ਗ਼ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ
Thank you :) Credit: NASA Earth Observatory/NOAA NGDC
ิࢿྉ
CommonClient public class CommonClient { private static final int
RETRY_COUNT = 3; private static final int RETRY_DELAY = 3; public static <T> Observable<T> retry(Observable<T> observable) { return observable.retryWhen(new Func1<Observable<? extends Throwable>, Observable<?>>() { @Override public Observable<?> call(Observable<? extends Throwable> observable) { return observable.take(RETRY_COUNT).flatMap(new Func1<Throwable, Observable<?>>() { @Override public Observable<?> call(Throwable throwable) { return Observable.timer(RETRY_DELAY, TimeUnit.SECONDS); } }); } }); } }
ApiClientGenerator public class ApiClientGenerator { public static <T> T
generate(Class<T> clazz, String baseUrl) { return new Retrofit.Builder() .client(HttpClient.getInstance()) .baseUrl(baseUrl) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build() .create(clazz); } }
HttpClient public class HttpClient { private static OkHttpClient instance;
private HttpClient() {} public static synchronized OkHttpClient getInstance() { if (instance == null) { HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); instance = new OkHttpClient.Builder() .addInterceptor(httpLoggingInterceptor) .addNetworkInterceptor(new StethoInterceptor()) .build(); } return instance; } }
GithubView public interface GithubView { void initViews(); void refresh();
void showProgressBar(); void hideProgressBar(); void setGithubContributors(List<GithubContributor> githubContributors); void startWebViewActivity(GithubContributor githubContributor); }
GithubUseCase public interface GithubUseCase { Observable<List<GithubContributor>> getGithubContributors(); }