Amplify - TDD on Android with Robolectric

Post on 10-May-2015

424 views 3 download

Tags:

description

Quick introduction to TDD on Android using Robolectric.

Transcript of Amplify - TDD on Android with Robolectric

The Magic of Android Unit TestingJohny Urgiles

Johny Urgiles

● 3 years @ Amplify ● Android dev for half of that● Code quality aficionado● The Lab for Robotics Education

Amplify & Test Driven Development

● Write test first ● See it fail● Write simplest possible solution● Refactor● Sleep peacefully at night

Finished Product

Slow & Careful

Slow & Careful

Slow & Careful

Fast & Risky

Slow & Careful

Fast & Risky

Android & TDD

● Android Instrumentation Unit Testing○ Pretty slow by unit test standards○ We still have to maintain a

separate infrastructure for tablet <-> tablet interaction

Android on JUnit

Stubbin

It’s Raining Runtime Exceptions

Robolectric 2.0

JVM

Robolectric

JUnit Test

Robolectric

● Mimics Android functionality● 2.0 includes Android code (4.2.1 rc1)● Provides view into Android internals● Extendable with ‘Shadows’

Robolectric @ Amplify

● 4500 unit tests across our Android Apps● Most in a single repo: 3751

○ Runs in 6.5 minutes (Macbook Pro)○ Migration to Robolectric 2.0 took a part-time dev

about 3 weeks○ Worth it

● Devs run unit tests in IntelliJ

Code Time

More Unit Testing @ Amplify

● RoboGuice○ Based on Google Guice○ Dependency injection for Android

● Mockito○ Standard Java Mock library

● Android FEST ○ Assertion library by Square