Book Image

Learning Android Application Testing

Book Image

Learning Android Application Testing

Overview of this book

Table of Contents (16 chapters)
Learning Android Application Testing
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Testing views in isolation


The test that we are analyzing here is based on the Focus2AndroidTest from the Android SDK ApiDemos project. It demonstrates how some properties of the Views that conform to a layout can be tested when the behavior itself cannot be isolated. The testing focusability of a view is one of these situations.

We are only testing individual views. In order to avoid creating the full Activity, this test extends AndroidTestCase. You may have thought about using just TestCase, but unfortunately, this is not possible as we need a Context to inflate the XML layout via LayoutInflater, and AndroidTestCase will provide us with this component:

public class FocusTest extends AndroidTestCase {
 private FocusFinder focusFinder;

 private ViewGroup layout;

 private Button leftButton;
 private Button centerButton;
 private Button rightButton;

@Override
protected void setUp() throws Exception {
 super.setUp();

 focusFinder = FocusFinder.getInstance();
 // inflate the layout
 Context...