Android Application Testing Guide

Android Application Testing Guide
eBook: $26.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $71.98    Print cover: $44.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • The first and only book that focuses on testing Android applications
  • Step-by-step approach clearly explaining the most efficient testing methodologies
  • Real world examples with practical test cases that you can reuse

Book Details

Language : English
Paperback : 332 pages [ 235mm x 191mm ]
Release Date : June 2011
ISBN : 1849513503
ISBN 13 : 9781849513500
Author(s) : Diego Torres Milano
Topics and Technologies : All Books, App Testing, Mobile Application Development, Android, Mobile

Table of Contents

Chapter 1: Getting Started with Testing
Chapter 2: Testing on Android
Chapter 3: Building Blocks on the Android SDK
Chapter 4: Test Driven Development
Chapter 5: Android Testing Environment
Chapter 6: Behavior Driven Development
Chapter 7: Testing Recipes
Chapter 8: Continuous Integration
Chapter 9: Performance Testing and Profiling
Chapter 10: Alternative Testing Tactics
  • Chapter 1: Getting Started with Testing
    • Brief history
    • Software bugs
      • How bugs severely affect your projects
    • Why, what, how, and when to test
      • What to test
        • Activity lifecycle events
        • Database and filesystem operations
        • Physical characteristics of the device
    • Types of tests
      • Unit tests
        • The test fixture
        • The setUp() method
        • The tearDown() method
        • Test preconditions
        • The actual tests
      • Integration tests
      • Functional or acceptance tests
        • Test case scenario
      • Performance tests
      • System tests
    • Android testing framework
      • Instrumentation
      • Test targets
    • Summary
    • Chapter 2: Testing on Android
      • JUnit
      • Creating the Android main project
      • Creating the Android test project
      • Package explorer
      • Creating a test case
        • Special methods
        • Test annotations
      • Running the tests
        • Running all tests from Eclipse
        • Running a single test case from Eclipse
        • Running from the emulator
        • Running tests from the command line
          • Running all tests
          • Running tests from a specific test case
          • Running a specific test by name
          • Running specific tests by category
          • Running performance tests
          • Dry run
      • Debugging tests
      • Other command-line options
      • Summary
      • Chapter 3: Building Blocks on the Android SDK
        • The demonstration application
        • Assertions in depth
          • Custom messages
          • Static imports
        • View assertions
        • Even more assertions
        • The TouchUtils class
        • Mock Objects
          • MockContext overview
          • The IsolatedContext class
          • Alternate route to file and database operations
          • The MockContentResolver class
        • The TestCase base class
          • The no-argument constructor
          • The given name constructor
          • The setName() method
        • The AndroidTestCase base class
          • The assertActivityRequiresPermission() method
            • Description
            • Example
          • The assertReadingContentUriRequiresPermission method
            • Description
            • Example
          • The assertWritingContentUriRequiresPermission() method
            • Description
            • Example
        • Instrumentation
          • The ActivityMonitor inner class
            • Example
        • The InstrumentationTestCase class
          • The launchActivity and launchActivityWithIntent method
          • The sendKeys and sendRepeatedKeys methods
          • The runTestOnUiThread helper method
        • The ActivityTestCase class
          • The scrubClass method
        • The ActivityInstrumentationTestCase2 class
          • The constructor
          • The setUp method
          • The tearDown method
          • The testPreconditions method
        • The ProviderTestCase2<T> class
          • The constructor
          • Example
        • The ServiceTestCase<T>
          • The constructor
        • The TestSuiteBuilder.FailedToCreateTests class
        • Using external libraries in test projects
        • Summary
        • Chapter 4: Test Driven Development
          • Getting started with TDD
            • Writing a test case
            • Running all tests
            • Refactoring the code
            • What is the advantage?
            • Understanding the requirements
          • Creating a sample project—the Temperature Converter
            • The list of requirements
            • User interface concept design
              • Creating the projects
          • Creating the TemperatureConverterActivityTests project
            • Creating the fixture
            • Test preconditions
            • Creating the user interface
            • Testing the existence of the user interface components
            • Getting the IDs defined
            • Translating requirements to tests
              • Empty fields
              • View properties
            • Screen layout
          • Adding functionality
            • Temperature conversion
            • The EditNumber class
            • TemperatureConverter unit tests
            • The EditNumber tests
            • The TemperatureChangeWatcher class
            • More TemperatureConverter tests
            • The InputFilter tests
          • Viewing our final application
          • Summary
          • Chapter 5: Android Testing Environment
            • Creating Android Virtual Devices
            • Running AVDs from the command line
              • Headless emulator
              • Disabling the keyguard
              • Cleaning up
              • Terminating the emulator
            • Additional emulator configurations
              • Simulating network conditions
              • Additional qemu options
            • Running monkey
              • Client-server monkey
            • Test scripting with monkeyrunner
              • Getting test screenshots
              • Record and playback
            • Summary
            • Chapter 6: Behavior Driven Development
              • Brief history
              • Given, when, then
              • FitNesse
                • Running FitNesse from the command line
                • Creating a TemperatureConverterTests subwiki
                  • Adding child pages to the subwiki
                  • Adding the acceptance test fixture
                  • Adding the supporting test classes
              • GivWenZen
                • Creating the test scenario
              • Summary
              • Chapter 7: Testing Recipes
                • Android Unit tests
                • Testing activities and applications
                  • Applications and preferences
                    • The RenamingMockContext class
                    • The TemperatureConverterApplicationTests class
                  • Testing activities
                • Testing files, databases, and ContentProviders
                  • The BrowserProvider tests
                • Testing exceptions
                • Testing local and remote services
                • Extensive use of mock objects
                  • Importing libraries
                  • The testTextChanged test
                  • Introducing Hamcrest
                    • Hamcrest matchers
                    • The hasToString matcher
                • Testing Views in isolation
                • Testing parsers
                  • Android assets
                  • The parser activity
                  • The parser test
                • Testing for memory leaks
                • Summary
                • Chapter 8: Continuous Integration
                  • Building Android applications manually using Ant
                  • Git—the fast version control system
                    • Creating a local git repository
                  • Continuous Integration with Hudson
                    • Installing and configuring Hudson
                    • Creating the jobs
                    • Obtaining Android test results
                  • Summary
                  • Chapter 9: Performance Testing and Profiling
                    • Ye Olde Logge method
                    • Performance tests in Android SDK
                      • Launching the performance test
                        • Creating the LaunchPerformanceBase instrumentation
                        • Creating the TemperatureConverterActivityLaunchPerformance class
                      • Running the tests
                    • Using the Traceview and dmtracedump platform tools
                    • Microbenchmarks
                      • Caliper microbenchmarks
                        • Creating the TemperatureConverterBenchmark project
                        • Running caliper
                    • Summary
                    • Chapter 10: Alternative Testing Tactics
                      • Building Android from source
                        • Code coverage
                          • EMMA features
                        • System requirements
                        • Downloading the Android source code
                          • Installing repo
                          • Creating the working copy
                          • The Building Steps
                      • TemperatureConverter code coverage
                        • Generating code coverage analysis report
                        • Covering the restoring the instance state
                        • Covering the exceptions
                        • Bypassing access restrictions
                        • Covering the options menu
                      • The undocumented Ant coverage target
                      • Introducing Robotium
                        • Downloading Robotium
                        • Configuring the project
                        • Creating the test cases
                          • The testFahrenheitToCelsiusConversion() test
                          • The testOnCreateOptionsMenu() revisited
                      • Testing on host's JVM
                        • Creating the TemperatureConverterJVMTest project
                        • Comparing the performance gain
                        • Adding Android to the picture
                      • Introducing Robolectric
                        • Installing Robolectric
                        • Creating a new Java project
                        • Writing some tests
                      • Summary

                      Diego Torres Milano

                      Diego Torres Milano has been involved with the Android platform since its inception, when he started exploring and researching the platform’s possibilities, mainly in the areas of User Interfaces, Unit and Acceptance Tests, and Test Driven Development. This is reflected from a number of articles published mainly on his personal blog ( and his participation as a lecturer in various conferences and courses such as Mobile Dev Camp 2008 in Amsterdam (Netherlands), and Japan Linux Symposium 2009 (Tokyo), Droidcon 2009 (London), Skillsmatter 2009 (London). He has also authored Android training courses delivered to various companies in Europe. Diego is the founder and developer of several Open Source projects, mainly CULT Universal Linux Thin Project, Autoglade, Gnome-tla, JGlade, and has been contributing to various Linux distributions such as RedHat, Fedora, and Ubuntu. Apart from giving presentations in Linux World, LinuxTag, GUADEC ES, University of Buenos Aires, etc, Diego has been developing software, participating in Open Source projects and advising companies worldwide for more than 15 years.

                      Code Downloads

                      Download the code and support files for this book.

                      Submit Errata

                      Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                      - 4 submitted: last submission 05 Mar 2014

                      Errata type: Typo | Page number: 19

                      The term "Intellij" is misspelled as "ItelliJ" in the following line:
                      "Other IDEs like ItelliJ..."


                      Errata type: Typo | Page number: 126

                      The term "DigitsKeyListener" is misspelled in the comment, as follows:
                      // DigistKeyListener.getInstance(true, true) returns an


                      Errata type: Technical | Page number: 116

                      The sentence "At the end of the test we set mEditNumber as a focusable View, that is it will be able to gain focus, as it will be participating in a bunch of tests simulating UIs that may need to request its focus explicitly." should read "At the end of the setUp() method we set mEditNumber as a focusable View, that is it will be able to gain focus, as it will be participating in a bunch of tests simulating UIs that may need to request its focus explicitly."


                      Errata type: Technical | Page number: 35

                      On page 35 the book states, "Looking carefully at the test definition you may find that we decorated the test using @MediumTest annotation." But the code example on page 35 has used '@SmallTest'.


                      Sample chapters

                      You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                      Frequently bought together

                      Android Application Testing Guide +    Microsoft Dynamics CRM 2011 Scripting Cookbook =
                      50% Off
                      the second eBook
                      Price for both: ₨351.00

                      Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                      What you will learn from this book

                      • Apply testing techniques and utilize tools to improve Android application development
                      • Learn the nuances of Unit and Functional testing and apply them to your Android projects
                      • Create sample Android test projects to try out your testing techniques
                      • Understand different development methodologies such as Test Driven Development and Behavior Driven Development
                      • Test different components such as Activities, ContentProvider, Services, and so on that make up an Android application
                      • Apply the Continuous Integration technique for ultimate application quality control
                      • Improve application performance by analyzing the results returned from performance tests
                      • Expose your application to a wide range of conditions and configurations to simulate real life network conditions and detect problems in the application

                      In Detail

                      It doesn't matter how much time you invest in Android design, or even how careful you are when programming; mistakes are inevitable and bugs will appear. This book will help you minimize the impact of these errors in your Android project and increase your development productivity. It will show you the problems that are easily avoided, to help get you quickly to the testing stage.

                      Android Application Testing Guide is the first and only book providing a practical introduction to the most common available techniques, frameworks, and tools to improve the development of your Android applications. Clear, step-by-step instructions show how to write tests for your applications and assure quality control using various methodologies.

                      The author's experience in applying application testing techniques to real world projects enables him to share insights on creating professional Android applications.

                      The book starts by introducing Test Driven Development, which is an agile component of the software development process and a technique where you will tackle bugs early on. From the most basic unit tests applied to a sample project to more sophisticated performance tests, this book provides a detailed description of the most widely used techniques in the Android testing world in a recipe-based approach.

                      The author has extensive experience of working on various development projects throughout his professional career. All this research and knowledge has helped create a book that will serve as a useful resource to any developer navigating the world of Android testing.


                      Android Application Testing Guide is a highly detailed book which gives step-by-step examples for a great variety of real-world cases, providing professional guidelines and recommendations that will be extremely valuable for optimizing your development time and resources. In the chapters you will find an introduction to specific testing techniques, and tools for specific situations.

                      Who this book is for

                      If you are an Android developer looking to test your applications or optimize your application development process, then this book is for you. No previous experience in application testing is required.

                      Code Download and Errata
                      Packt Anytime, Anywhere
                      Register Books
                      Print Upgrades
                      eBook Downloads
                      Video Support
                      Contact Us
                      Awards Voting Nominations Previous Winners
                      Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                      Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software