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 ...

Get Learning Android Application Testing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.