$30 off During Our Annual Pro Sale. View Details »

How Android Testing changed how we think about death...

Tuenti
November 10, 2013

How Android Testing changed how we think about death...

"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.

Tuenti

November 10, 2013
Tweet

More Decks by Tuenti

Other Decks in Technology

Transcript

  1. 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

    View Slide

  2. Who am I…
    •  Software Engineer
    •  GDG Barcelona Organizer
    •  Android lover
    •  Geek
    •  Gintonic fan…
    …y un pelotudo…

    View Slide

  3. Agenda?

    View Slide

  4. 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.

    View Slide

  5. Martin Fowler:
    "...test-doubles ... preprogrammed with
    expectation"
    What is this mock thing?

    View Slide

  6. 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

    View Slide

  7. Mockito
    Build-operate-check pattern

    View Slide

  8. Mock initizalition

    View Slide

  9. Initizalition using mockito test runner

    View Slide

  10. Let’s verify some behaviour

    View Slide

  11. Argument matchers

    View Slide

  12. Verifying number of invocations / at
    least x / never

    View Slide

  13. Making sure interaction(s) never
    happened on mock

    View Slide

  14. Spying on real objects

    View Slide

  15. Sounds familiar???

    View Slide

  16. Allows you to run your android
    code on JVM.
    Allows loading of Android
    Classes in pure Java
    Projects.
    TO THE RESCUE…

    View Slide

  17. Shadow Objects!

    View Slide

  18. View and Resource Loading…

    View Slide

  19. Shadow Activity
    Shadow ImageView

    View Slide

  20. •  Uses real Android SDK code
    •  Styles and themes supported
    •  System resources are available
    •  Performance improved
    •  Bugs fixed
    Robolectric 2.0+

    View Slide

  21. Perform click Sample

    View Slide

  22. Started Activity test
    Should have fragment test

    View Slide

  23. Device Configuration Sample

    View Slide

  24. Network sample
    Robolectric acts as a proxy!!!

    View Slide

  25. Creating your own shadows

    View Slide

  26. Creating your own shadows

    View Slide

  27. Creating your own shadows

    View Slide

  28. •  A library by square (FTW!)
    •  It gives a chainable (or “fluent”)
    syntax for checking assertions.
    •  Makes tests easier to write (and
    read!).
    FEST Android

    View Slide

  29. Sample: code to modify a bitmap

    View Slide

  30. Assertions with FEST

    View Slide

  31. 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?

    View Slide

  32. Dagger
    Directed
    Acyclic
    Graph

    View Slide

  33. Dagger Graph sample

    View Slide

  34. Dagger sample

    View Slide

  35. Declare dependencies

    View Slide

  36. Satisfy dependencies

    View Slide

  37. Build the graph

    View Slide

  38. Modules

    View Slide

  39. Spoon
    •  Acceptance tests (black box)
    •  Automation of test execution across multiple
    devices
    •  Aggregation of the results

    View Slide

  40. Spoon
    •  Aggregation of screenshots while your tests
    are running

    View Slide

  41. •  Robojuice
    •  Robotium
    •  Android Testing Framework
    •  UI Automator
    •  Monkey Runner
    More tools…

    View Slide

  42. 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…

    View Slide

  43. View Slide

  44. Questions?

    View Slide

  45. @fernando_cejas
    https://github.com/android10
    [email protected]
    http://corporate.tuenti.com/es/dev/blog
    THANKS!!!

    View Slide