Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Introduction: Testing

Published? true
FormatLanguage: WikiFormat

Problem:

N/A

Discussion:

Test early and often is a common cry among advocates of testing. As is the all-important question "If you don't have a test, how do you know your code works?"

There are many types of testing. Unit Testing checks out individual components in isolation (not hitting the network or the database). JUnit and TestNG are the leading frameworks here. Mock Objects are used where interaction with other components is required; there are several good mocking frameworks for Java.

Android provides an Application Testing facility. We have a recipe on it 3352 here. Android's popularity, and the complexity of apps, ensures that there will be many testing frameworks developed for Android. Third-party testing frameworks include those shown in Table 1. If you know of others, please leave a comment on this Recipe or send an email to the site administrator; thanks!

Third-Party Testing Frameworks
Name Elevator Pitch Web Site Recipe Ref
Robolectric Unit testing w/o loading on emulator [1] Pending
Robotium "Black Box" testing w/o app source code http://code.google.com/p/robotium/ Pending
Calabash Feature-based (Cucumber) testing (needs Ruby on dev machine) https://github.com/calabash/calabash-android Pending

The terms NPE, ANR, and FC are used without further explanation in this chapter. NPE is a "traditional Java" acronym for Null Pointer Exception. ANR is an Android-specific acronym; it stands for Application Not Responding, the first few words of a dialog you get when your application is judged by Android to be taking too long to respond to a request. FC stands for Force Close, which occurs when Android requests that you close a failed application.