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

The ProviderTestCase2<T> class


This is a test case designed to test the ContentProvider classes.

The ProviderTestCase2 class also extends AndroidTestCase. The class template parameter T represents ContentProvider under test. Implementation of this test uses IsolatedContext and MockContentResolver, which are mock objects that we described before in this chapter.

The constructor

There is only one public non-deprecated constructor for this class. This is as follows:

ProviderTestCase2(Class<T> providerClass, String providerAuthority)

This should be invoked with an instance of the ContentProvider class for the same ContentProvider class used as a class template parameter.

The second parameter is the authority for the provider, which is usually defined as the AUTHORITY constant in the ContentProvider class.

An example

This is a typical example of a ContentProvider test:

public void testQuery() {
    String segment = "dummySegment";
    Uri uri = Uri.withAppendedPath(MyProvider.CONTENT_URI,...