Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

PareshMayani.apk Founder/Organizer, GDG Ahmedabad Technical Lead @ Lets Nurture Application Architect

Slide 3

Slide 3 text

Good/Clean code base? What is that? Why should we have good/clean code base?

Slide 4

Slide 4 text

Scalable

Slide 5

Slide 5 text

Scalable | Stable

Slide 6

Slide 6 text

Scalable | Stable | Testable

Slide 7

Slide 7 text

Scalable | Stable | Testable | Modular

Slide 8

Slide 8 text

Application Architecture? And why do I care?

Slide 9

Slide 9 text

MV* Patterns? And why do I care?

Slide 10

Slide 10 text

MV (C | P | VM) Model Business logic Data source of the application Network layer, database operations

Slide 11

Slide 11 text

MV (C | P | VM) View Business logic Data source of the application Network layer, database operations Responsible for displaying data Model

Slide 12

Slide 12 text

MVC Model View Controller

Slide 13

Slide 13 text

View Model Controller Controller manipulates, edit, uses data model and show it to users via View.

Slide 14

Slide 14 text

View Model Controller In Android, Activity/Fragments can act as both View and Controller

Slide 15

Slide 15 text

MVP Model View Presenter

Slide 16

Slide 16 text

Presenter Model View 1 .. 1

Slide 17

Slide 17 text

Presenter Model View 1 .. 1 Presenter is a simple java class that do not contain any UI components, it just manipulates data from model and display in on View.

Slide 18

Slide 18 text

MVVM Model View ViewModel

Slide 19

Slide 19 text

ViewModel Model View 1 .. * Many View can be mapped to one View-Model

Slide 20

Slide 20 text

MVC vs MVP vs MVVM Show me flow how it actually works

Slide 21

Slide 21 text

Passes call to Fire events Manipulates Model-View-Controller Controller Model View User Interaction

Slide 22

Slide 22 text

Passes call to Fire events Manipulates Model-View-Controller Controller Model View User Interaction Passes call to Manipulates Model-View-Presenter Presenter Model View Updates User Interaction Fire events

Slide 23

Slide 23 text

Passes call to Fire events Manipulates Model-View-Controller Controller Model View User Interaction Passes call to Manipulates Model-View-Presenter Presenter Model View Bi-directional Data Binding Manipulates Model-View-ViewModel ViewModel Model View Updates User Interaction User Interaction Fire events Fire events

Slide 24

Slide 24 text

MVC vs MVP vs MVVM Which one to follow?

Slide 25

Slide 25 text

Activity/Fragment/View should be Business logic free

Slide 26

Slide 26 text

Can you unit test everything?

Slide 27

Slide 27 text

Unit Testing Why to test?

Slide 28

Slide 28 text

Local unit tests Instrumented tests Test Types

Slide 29

Slide 29 text

Located at module-name/src/test/java/. These tests run on the local JVM and do not have access to functional Android framework APIs. Local unit tests

Slide 30

Slide 30 text

Located at module-name/src/androidTest/java/. These are all tests that must run on an Android hardware device or an Android emulator. Instrumented (end-to-end) tests

Slide 31

Slide 31 text

1) Instrumented test 2) Local JVM Test

Slide 32

Slide 32 text

Why Unit Testing? Why should we write unit test?

Slide 33

Slide 33 text

“Unit Testing is a level of software testing where individual units/ components of a software are tested. “ The purpose is to validate that each unit of the software performs as designed.” All possible scenarios

Slide 34

Slide 34 text

Unit tests are for the software developers Unit tests are written by software developers

Slide 35

Slide 35 text

Options: JUnit, Robolectric Frameworks: Mockito, PowerMock Unit Testing

Slide 36

Slide 36 text

Mocking => @mock @spy Stubbing => when().thenreturn(true/false) Verifying => verify() Mockito

Slide 37

Slide 37 text

// You can mock concrete classes and interfaces TrainSeats seats = mock(TrainSeats.class); // stubbing appears before the actual execution when(seats.book(Seat.near(WINDOW).in(FIRST_CLASS))).thenReturn(BOOKED); // the following prints "BOOKED" System.out.println(seats.book(Seat.near(WINDOW).in(FIRST_CLASS))); // the following prints "null" because .book(Seat.near(AISLE).in(FIRST_CLASS))) was not stubbed System.out.println(seats.book(Seat.near(AISLE).in(FIRST_CLASS))); // the following verification passes because .book(Seat.near(WINDOW).in(FIRST_CLASS)) has been invoked verify(seats).book(Seat.near(WINDOW).in(FIRST_CLASS)) // the following verification fails because .book(Seat.in(SECOND_CLASS)) has not been invoked verify(seats).book(Seat.in(SECOND_CLASS)) Example

Slide 38

Slide 38 text

Options: Robotium, Espresso Firebase Test lab support Android Studio test recorder Instrumentation tests

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Continuous Integration Can I perform unit testing automatically whenever software builds?

Slide 42

Slide 42 text

Jenkins (Open source) Travis / Circle CI / Atlanssian Bamboo Performs testing on triggering actions like PR merge Automated reporting: Send email if build fails Auto publishing to play store Continuous Integration

Slide 43

Slide 43 text

Demo Time MVP Pattern & Unit Testing

Slide 44

Slide 44 text

https://goo.gl/Z4dy8G https://github.com/googlesamples/android-architecture Resources

Slide 45

Slide 45 text

No Questions!

Slide 46

Slide 46 text

Thank you! Paresh Mayani @pareshmayani Grab This Presentation https://goo.gl/Xsvpi3