![Page 1: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/1.jpg)
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
![Page 2: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/2.jpg)
Who am I…
• Software Engineer • GDG Barcelona Organizer • Android lover • Geek • Gintonic fan…
…y un pelotudo…
![Page 3: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/3.jpg)
Agenda?
![Page 4: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/4.jpg)
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.
![Page 5: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/5.jpg)
Martin Fowler: "...test-doubles ... preprogrammed with
expectation"
What is this mock thing?
![Page 6: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/6.jpg)
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
![Page 7: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/7.jpg)
Mockito Build-operate-check pattern
![Page 8: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/8.jpg)
Mock initizalition
![Page 9: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/9.jpg)
Initizalition using mockito test runner
![Page 10: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/10.jpg)
Let’s verify some behaviour
![Page 11: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/11.jpg)
Argument matchers
![Page 12: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/12.jpg)
Verifying number of invocations / at least x / never
![Page 13: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/13.jpg)
Making sure interaction(s) never happened on mock
![Page 14: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/14.jpg)
Spying on real objects
![Page 15: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/15.jpg)
Sounds familiar???
![Page 16: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/16.jpg)
Allows you to run your android code on JVM.
Allows loading of Android Classes in pure Java Projects.
TO THE RESCUE…
![Page 17: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/17.jpg)
Shadow Objects!
![Page 18: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/18.jpg)
View and Resource Loading…
![Page 19: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/19.jpg)
Shadow Activity
Shadow ImageView
![Page 20: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/20.jpg)
• Uses real Android SDK code • Styles and themes supported • System resources are available • Performance improved • Bugs fixed
Robolectric 2.0+
![Page 21: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/21.jpg)
Perform click Sample
![Page 22: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/22.jpg)
Started Activity test
Should have fragment test
![Page 23: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/23.jpg)
Device Configuration Sample
![Page 24: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/24.jpg)
Network sample
Robolectric acts as a proxy!!!
![Page 25: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/25.jpg)
Creating your own shadows
![Page 26: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/26.jpg)
Creating your own shadows
![Page 27: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/27.jpg)
Creating your own shadows
![Page 28: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/28.jpg)
• A library by square (FTW!) • It gives a chainable (or “fluent”)
syntax for checking assertions. • Makes tests easier to write (and
read!).
FEST Android
![Page 29: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/29.jpg)
Sample: code to modify a bitmap
![Page 30: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/30.jpg)
Assertions with FEST
![Page 31: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/31.jpg)
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?
![Page 32: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/32.jpg)
Dagger
Directed Acyclic Graph
![Page 33: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/33.jpg)
Dagger Graph sample
![Page 34: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/34.jpg)
Dagger sample
![Page 35: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/35.jpg)
Declare dependencies
![Page 36: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/36.jpg)
Satisfy dependencies
![Page 37: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/37.jpg)
Build the graph
![Page 38: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/38.jpg)
Modules
![Page 39: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/39.jpg)
Spoon • Acceptance tests (black box) • Automation of test execution across multiple
devices • Aggregation of the results
![Page 40: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/40.jpg)
Spoon • Aggregation of screenshots while your tests
are running
![Page 41: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/41.jpg)
• Robojuice • Robotium • Android Testing Framework • UI Automator • Monkey Runner
More tools…
![Page 42: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/42.jpg)
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…
![Page 43: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/43.jpg)
![Page 44: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/44.jpg)
Questions?
![Page 45: How ANDROID TESTING changed how we think about Death](https://reader034.vdocument.in/reader034/viewer/2022042502/554a1c02b4c9055c598b54ef/html5/thumbnails/45.jpg)
@fernando_cejas https://github.com/android10
[email protected] http://corporate.tuenti.com/es/dev/blog
THANKS!!!