15
ANDROID TESTING Chris Bowling

Android testing patterns

Embed Size (px)

Citation preview

Page 1: Android testing patterns

ANDROID TESTING

Chris Bowling

Page 2: Android testing patterns

CONSIDERATIONS

Define

Unit Test

Instrumentation

Integration

Functional

Component

UI

Decouple

Code needs to be written with testing in mind

Decouple your code and from Android as much as possible

How?

1. Reduce dependencies on Android, fragments

2. Leverage libraries (Dagger, Butterknife, Robobindings)

Page 3: Android testing patterns

CONSIDERATIONS

Defend

Establish clear component boundaries

Unit tests? – do they have Android dependencies

Leverage testing libriaries (Jmockit, WireMock, Robolectric, Appium)

Deploy

Precommit builds – run unit tests, lint

Continuous or Nightly jobs – run integration and UI tests

Releases – get your builds out there

1. Alpha and beta builds

2. Frequent production releases

Page 4: Android testing patterns

CASE STUDIESConsideration Case 1 Case 2

Define -Unit: fast

-Functional: slow

-95%+ code coverage mandate

-Code reviews before commit

-Unit:No android dependencies

-Integration: boundaries around components

-UI: Fully end to end

-No code coverage mandate

Decouple -Very coupled

-Code and then write tests to get coverage

-Decoupled code

-Dagger all the things

-No fragments

-Decoupled from Android

Defend -Use all the things

-Do all the things

-Just get 95% coverage

-Each component had clear responsibilities

-Reduced need for unit tests

-Small integration tests

Deploy -Precommit builds run all tests

-Nightly builds

-Two week release cycle

-Precommit build runs Unit tests

-Continuous builds run integration and UI tests

-Daily alpha / Weekly beta builds

-Two week release cycle

Page 5: Android testing patterns

TAKE AWAYS

One size does not fit all - find a solution that works for your team and take ownership

Testing is like an exercise program – you get results when you stick with it

Any step forward is a step in the right direction

Page 6: Android testing patterns

eCG android tests

Page 7: Android testing patterns

Testing Pyramid

End-to-End Test

Integration Tests

Unit Tests

Page 8: Android testing patterns

Unit Tests

True Unit Tests – use BDD principals

~2200 tests /~40 seconds

Running with jUnit (not on emulator)

Dependency Injection

Mocking using Mockito

Ctor injection

MVP pattern for testing UI logic

Use Robolectic to allow for mocked android components

Shared prefs, app instance, etc

Avoid mocking Fragments/Activities/Views

Page 9: Android testing patterns

UI Tests

Full end to end tests

Uses BDD principals

Cucumber driver running Espresso

Built and maintained by QE engineers

60% app coverage, runs in ~4.5 hours

Page 10: Android testing patterns

Integration Tests

Creation in progress

BDD tests using cucumber – same as UI tests

Will inject the network layer to allow for faster and more robust tests

Page 11: Android testing patterns

Ben Yarger

QE Lead

eBay for Charity

Page 12: Android testing patterns

Bio

• 4 years at eBay

• RedLaser SDK (Android & iOS)

• Mobile Architecture (Android)

• eBay for Charity (full stack)

Page 13: Android testing patterns
Page 14: Android testing patterns
Page 15: Android testing patterns

View

Controller

Model

Vie

w It

em

Sear

ch

Ch

eck

ou

t

Cu

sto

mer

Co

nn

ecti

on

AppServices

Customer Connection

Checkout

Search

View Item