Book Image

Android Application Testing Guide

By : Diego Torres Milano
Book Image

Android Application Testing Guide

By: Diego Torres Milano

Overview of this book

<p>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.<br /><br />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.<br /><br />The author's experience in applying application testing techniques to real world projects enables him to share insights on creating professional Android applications. <br /><br />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.<br /><br />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.</p>
Table of Contents (17 chapters)
Android Application Testing Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The TouchUtils class


Sometimes, when testing UIs, it is helpful to simulate different kinds of touch events. These touch events can be generated in many different ways but probably android.test.TouchUtils is the simplest to use. This class provides reusable methods for generating touch events in test cases that are derived from InstrumentationTestCase.

Featured methods allow simulated interaction with the UI under test. TouchUtils provides the infrastructure to inject the events using the correct UI or main thread, so no special handling is needed and you don't need to annotate the test using @UIThreadTest.

The mentioned methods support:

  • Clicking on a View and releasing it

  • Tapping on a View, that is touching it and quickly releasing

  • Long clicking on a View

  • Dragging the screen

  • Dragging Views

The following test represents a typical usage of TouchUtils:

  public void testListScrolling() {
    mListView.scrollTo(0, 0);
    TouchUtils.dragQuarterScreenUp(this, mActivity);
    TouchUtils.dragQuarterScreenUp...