I <3 Android
• CodePath August 2013
• Then: EroGear LED control app
• Now: Android lead at Mango Health
• Why test Android projects? What’s your approach?
• Android testing libraries
• How to write tests
• How to automate test runs
TDD and BDD
• TDD seems like a tough goal. Start small!
• BDD creates strong functional tests
• Behavior-driven dev healthy testing practices
Your goal? Release with confidence.
What to test
• Identify activity pathways in your app
• Test user stories with BDD strategies
• Test concepts like:
• button clicks perform actions
• content is drawn on screen
• an intent was launched and finished as expected
Database & services
What to test
Which library is best?
• Robolectric is fast: no emulator required
• Robotium oﬀers flexibility, if the emulator doesn’t bog
Robolectric, Robotium, Android built-in tests, Mockito...?
OK to use more than one! You’ll probably have to.
BDD: Robolectric first , then Robotium.
Don’t forget plain old JUnit.
• Starts its own emulator or can be run on your Android
device... so it’s slow
• Runs as separate Android project linked to main
• Based on Android Instrumentation built-in tests
• Provides implementation for Android native methods,
lets you write behavior tests that use them directly
• Runs as a JUnit test project, not an Android app
• Fast! No emulator necessary
• Where it works, it’s awesome
(more code examples, but a little dated)
Good Ideas in Testing
• Multiple assertions per test are OK
• Test only one concept per test method
• You can write multiple test methods for one UI story
• Don’t test other libraries’code
• Look for ways to simplify your tests
Building with Tests
The goal of test coverage is to avoid manual work.
How do you run automated tests?
You rang, sir?
Your Basic CI Setup
Write tests in your IDE
Commit projects to a build server
Run build scripts
Deploy tested .apk as dev build
Eclipse, Android Studio
Jenkins with Git hooks
Hockey, XL Studio
Details on the CodePath wiki!
• Running CI with Gradle, you can configure build.gradle
to run your Robolectric and your JUnit tests
• Develop locally in Android Studio
• Run tests with
• Then push the dev configuration to your CI
environment’s build.gradle file
You really should…
Set up deployment tool to distribute .apk
(XL Studio or HockeyApp)
Write a build script that sends .apk
from Jenkins to deployment tool
Configure Jenkins to:
Write test projects1
1. run test projects as part of build
2. start a new build whenever you push code
Write tests and features Push code to repo
Jenkins runs the test projects
as part of the .apk build
New .apk gets sent out to
Read Jenkins logs
Try, try again
Robotium in CI?
• Configure Jenkins to launch an emulator
• Use the Android Emulator Plugin
• Big thanks to Nathan & Tim
• Contribute to the CodePath wiki!
• Stay in touch?
• Also, we’re hiring.