Deprecated platform Android testing APIs

- Deprecated most android.test.* APIs
- Kept ProviderTestCase2 and LoaderTestCase since we don't have a
replacement yet
- Deprecated android.test.suitebuilder
- Added Javadoc to all deprecated APIs with links to corresponding
Android Testing Support Library APIs
- Removed all trailing whitespace

Bug: 22314304
Change-Id: I1b1f0dd5132364110f1dfd4e3eb2dd044700d859
This commit is contained in:
Stephan Linzner
2016-01-27 18:09:50 -08:00
parent d11c15d418
commit b51617f466
57 changed files with 548 additions and 374 deletions

View File

@@ -32,7 +32,7 @@ import android.content.Context;
* In order to support the lifecycle of a Application, this test case will make the
* following calls at the following times.
*
* <ul><li>The test case will not call onCreate() until your test calls
* <ul><li>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().</li>
@@ -40,22 +40,28 @@ import android.content.Context;
* automatically called, and it will stop & destroy your application by calling its
* onDestroy() method.</li>
* </ul>
*
*
* <p><b>Dependency Injection.</b>
* 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
* This framework allows you to inject a modified, mock, or isolated replacement for this
* dependencies, and thus perform a true unit test.
*
*
* <p>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
* You can create and inject alternative types of Contexts by calling
* {@link AndroidTestCase#setContext(Context) setContext()}. You must do this <i>before</i> 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
* number of alternatives for Context, including {@link android.test.mock.MockContext MockContext},
* {@link android.test.RenamingDelegatingContext RenamingDelegatingContext}, and
* {@link android.content.ContextWrapper ContextWrapper}.
*
* @deprecated Use
* <a href="{@docRoot}reference/android/support/test/InstrumentationRegistry.html">
* InstrumentationRegistry</a> instead. New tests should be written using the
* <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a>.
*/
@Deprecated
public abstract class ApplicationTestCase<T extends Application> extends AndroidTestCase {
Class<T> mApplicationClass;
@@ -78,17 +84,17 @@ public abstract class ApplicationTestCase<T extends Application> extends Android
}
/**
* This will do the work to instantiate the Application under test. After this, your test
* This will do the work to instantiate the Application under test. After this, your test
* code must also start and stop the Application.
*/
@Override
protected void setUp() throws Exception {
super.setUp();
// get the real context, before the individual tests have a chance to muck with it
mSystemContext = getContext();
}
/**
* Load and attach the application under test.
*/
@@ -101,26 +107,26 @@ public abstract class ApplicationTestCase<T extends Application> extends Android
}
mAttached = true;
}
/**
* Start the Application under test, in the same way as if it was started by the system.
* Start the Application under test, in the same way as if it was started by the system.
* If you use this method to start the Application, it will automatically
* be stopped by {@link #tearDown}. If you wish to inject a specialized Context for your
* test, by calling {@link AndroidTestCase#setContext(Context) setContext()},
* test, by calling {@link AndroidTestCase#setContext(Context) setContext()},
* you must do so before calling this method.
*/
final protected void createApplication() {
assertFalse(mCreated);
if (!mAttached) {
setupApplication();
}
assertNotNull(mApplication);
mApplication.onCreate();
mCreated = true;
}
/**
* This will make the necessary calls to terminate the Application under test (it will
* call onTerminate(). Ordinarily this will be called automatically (by {@link #tearDown}, but
@@ -131,13 +137,13 @@ public abstract class ApplicationTestCase<T extends Application> extends Android
mApplication.onTerminate();
}
}
/**
* Shuts down the Application under test. Also makes sure all resources are cleaned up and
* Shuts down the Application under test. Also makes sure all resources are cleaned up and
* garbage collected before moving on to the next
* test. Subclasses that override this method should make sure they call super.tearDown()
* at the end of the overriding method.
*
*
* @throws Exception
*/
@Override
@@ -145,7 +151,7 @@ public abstract class ApplicationTestCase<T extends Application> extends Android
terminateApplication();
mApplication = null;
// Scrub out members - protects against memory leaks in the case where someone
// Scrub out members - protects against memory leaks in the case where someone
// creates a non-static inner class (thus referencing the test case) and gives it to
// someone else to hold onto
scrubClass(ApplicationTestCase.class);
@@ -156,7 +162,7 @@ public abstract class ApplicationTestCase<T extends Application> extends Android
/**
* Return a real (not mocked or instrumented) system Context that can be used when generating
* Mock or other Context objects for your Application under test.
*
*
* @return Returns a reference to a normal Context.
*/
public Context getSystemContext() {
@@ -165,7 +171,7 @@ public abstract class ApplicationTestCase<T extends Application> extends Android
/**
* This test simply confirms that the Application class can be instantiated properly.
*
*
* @throws Exception
*/
final public void testApplicationTestCaseSetUpProperly() throws Exception {