ProviderTestCase2
You test a provider with a subclass ofProviderTestCase2. This base class
extends AndroidTestCase, so it provides the JUnit testing framework as well
as Android-specific methods for testing application permissions. The most important
feature of this class is its initialization, which creates the isolated test environment.
The initialization is done in the constructor for
ProviderTestCase2, which
subclasses call in their own constructors. The ProviderTestCase2
constructor creates an IsolatedContext object that allows file and
database operations but stubs out other interactions with the Android system.
The file and database operations themselves take place in a directory that is local to the
device or emulator and has a special prefix.
The constructor then creates a
MockContentResolver to use as the
resolver for the test. The MockContentResolver class is described in
detail in the section
Mock object
classes.
Lastly, the constructor creates an instance of the provider under test. This is a normal
ContentProvider object, but it takes all of its environment information
from the IsolatedContext, so it is restricted to
working in the isolated test environment. All of the tests done in the test case class run
against this isolated object.
RSS Feed
Twitter
0 comments:
Post a Comment