testing in android€¦ · android architecture • mvc: model view controller • mvp: model view...

22
Testing in Android Soham Mondal Founder, Triveous

Upload: others

Post on 22-May-2020

26 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

TestinginAndroid

SohamMondalFounder,Triveous

Page 2: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

About me

- Founder,Triveous- Creator,VoiceRecorder- GoogleExpert:UX- Android/UXconsultant- OrganizeratBlrdroid- MentorattheGoogleLaunchpadAccelerator

Page 3: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Agenda

• Androidarchitecture:MVP/MVVM/MVC?• WhatisTesting?Testingprinciples• TypesofTests• Unittesting• Demo:UnitTesting• InstrumentationTesting• Demo:Instrumentationtesting• ContinuousIntegration

Page 4: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Android Architecture

• MVC:ModelViewController• MVP:ModelViewPresenter• MVVM:ModelViewViewModel• CleanArchitecturebyUncleBob

Page 5: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Clean Architecture

• Framework• SlavesoftheFramework• SeparatebusinesslogicfromFramework• Activities/Fragments• Entanglement• ImpactsPortability/Maintainability/Clarityofthesolution

Page 6: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

MVP

• Presenter• InjectingpresenterintoViews

• Canunittestthepresenter

http://hannesdorfmann.com/mosby/mvp/

Page 7: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

TESTINGTestinghelpscreategreat,stable,maintainableandscalableapps

Page 8: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Testing Principles

• Cleanarchitecture• Understandwhatyou’retryingtotest• Isolation• Integration• Allpossiblescenarios• TDD

Page 9: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Type of Tests

• Unittests• Integrationtests• Endtoendtests(Instrumentationtests)

http://googletesting.blogspot.in/2015/04/just-say-no-to-more-end-to-end-tests.html

Page 10: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Objective of Unit Testing?

• Justthecorefunctionality/business logic• Noexternaldependencies• Quickandpredictable• Allpossiblescenarios• TDD

Page 11: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Unit Testing

• Options:Roboelectric,JUnit• Unittestingonandroidstudio• Mockito• PowerMock

Page 12: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Mockito

-@mock-when/thenReturn-@spy-verify-@ArgumentCaptor

Page 13: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

UNITTESTDEMO

Page 14: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Objective:Whatareyoutesting?

• Endtoendfunctionality• UI• Externaldependencies• Longer• Flaky

Page 15: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

Instrumentation tests

• Options:Robotium,Espresso• Whyisespressogenerallybetter?• Espressotestrecorderinandroidstudio• Supportforfirebasetestlab

Page 16: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob
Page 17: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob
Page 18: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

ESPRESSODEMO

Page 19: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

More Espresso

• Espresso-IntentsandIntentStubbing• Espresso-ContribforDatePicker,RecyclerView,Draweractions,Accessibilitychecks,CountingIdlingResource

• Idlingresources• Codecoverage

Page 20: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

CONTINUOUSINTEGRATION

Page 21: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob

CI

• Jenkins• Travis/CircleCI/others• Integrationwithgithubandothers• Automatedreporting:Email/Updateslack• Deploytoplaystore

Page 22: testing in android€¦ · Android Architecture • MVC: Model View Controller • MVP: Model View Presenter • MVVM: Model View ViewModel • Clean Architecture by UncleBob