O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Android Application Testing Guide

Book Description

This book assumes no prior experience of testing your Android applications and introduces you to all the most effective techniques and tools. It digs deep with real-life examples to make learning easy and interesting.

  • 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

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.

Table of Contents

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