how android testing changed how we think about death

Post on 06-May-2015

614 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

"Irreproducible bugs become highly reproducible right after delivery to the customer". This is something that happens "almost" everyday. It is well known that testing offers significant advantages as a development practice and helps ensure higher quality code with fewer defects. Unfortunately, testing Android apps can be challenging, so in this session we are gonna talk about available tools and practices that could help us accomplish our goals.

TRANSCRIPT

How ANDROID TESTING changed how we think about death…

@fernando_cejas

Code samples: https://github.com/android10/Inside_Android_Testing https://github.com/android10/AndroidApplicationTestingSample

Who am I…

•  Software Engineer •  GDG Barcelona Organizer •  Android lover •  Geek •  Gintonic fan…

…y un pelotudo…

Agenda?

Why testing..WTF?

•  Testing increases the level of confidence in your code.

•  Testing makes it possible to write new code, and refactor existing code, without worrying that you’ve broken existing functionality.

Martin Fowler: "...test-doubles ... preprogrammed with

expectation"

What is this mock thing?

Mockito is a mocking framework that tastes really good.

Mockito doesn't give you hangover because the tests are very readable and they produce clean verification errors.

GIVE A WARM WELCOME TO… mockito

Mockito Build-operate-check pattern

Mock initizalition

Initizalition using mockito test runner

Let’s verify some behaviour

Argument matchers

Verifying number of invocations / at least x / never

Making sure interaction(s) never happened on mock

Spying on real objects

Sounds familiar???

Allows you to run your android code on JVM.

Allows loading of Android Classes in pure Java Projects.

TO THE RESCUE…

Shadow Objects!

View and Resource Loading…

Shadow Activity

Shadow ImageView

•  Uses real Android SDK code •  Styles and themes supported •  System resources are available •  Performance improved •  Bugs fixed

Robolectric 2.0+

Perform click Sample

Started Activity test

Should have fragment test

Device Configuration Sample

Network sample

Robolectric acts as a proxy!!!

Creating your own shadows

Creating your own shadows

Creating your own shadows

•  A library by square (FTW!) •  It gives a chainable (or “fluent”)

syntax for checking assertions. •  Makes tests easier to write (and

read!).

FEST Android

Sample: code to modify a bitmap

Assertions with FEST

Dependency injection is a software design pattern that allows the removal of hard-coded dependencies and makes it possible to change

them, whether at run-time or compile-time

Dependency what?

Dagger

Directed Acyclic Graph

Dagger Graph sample

Dagger sample

Declare dependencies

Satisfy dependencies

Build the graph

Modules

Spoon •  Acceptance tests (black box) •  Automation of test execution across multiple

devices •  Aggregation of the results

Spoon •  Aggregation of screenshots while your tests

are running

•  Robojuice •  Robotium •  Android Testing Framework •  UI Automator •  Monkey Runner

More tools…

WRITE TESTS!!!

•  Simplify your architecture •  Have a robust testing strategy •  Use continuous integration tools •  Mock/stub functionality •  Create your own test runner

Best practices and some advice…

Questions?

@fernando_cejas https://github.com/android10

jobs@tuenti.com http://corporate.tuenti.com/es/dev/blog

THANKS!!!

top related