This test case provides a framework in which you can test Application classes in
a controlled environment. It provides basic support for the lifecycle of a
Application, and hooks by which you can inject various dependencies and control
the environment in which your Application is tested.
Lifecycle Support.
Every Application is designed to be accessed within a specific sequence of
method calls (see {@link android.app.Application} for more details).
In order to support the lifecycle of a Application, this test case will make the
following calls at the following times.
- The test case will not call onCreate() until your test calls
{@link #createApplication()}. This gives you a chance
to set up or adjust any additional framework or test logic before
onCreate().
- After your test completes, the test case {@link #tearDown} method is
automatically called, and it will stop & destroy your application by calling its
onDestroy() method.
Dependency Injection.
Every Application has one inherent dependency, the {@link android.content.Context Context} in
which it runs.
This framework allows you to inject a modified, mock, or isolated replacement for this
dependencies, and thus perform a true unit test.
If simply run your tests as-is, your Application will be injected with a fully-functional
Context.
You can create and inject alternative types of Contexts by calling
{@link AndroidTestCase#setContext(Context) setContext()}. You must do this before calling
{@link #createApplication()}. The test framework provides a
number of alternatives for Context, including {@link android.test.mock.MockContext MockContext},
{@link android.test.RenamingDelegatingContext RenamingDelegatingContext}, and
{@link android.content.ContextWrapper ContextWrapper}. |