java.lang.Object | |||||
↳ | junit.framework.Assert | ||||
↳ | junit.framework.TestCase | ||||
↳ | android.test.InstrumentationTestCase | ||||
↳ | android.test.ActivityTestCase | ||||
↳ | android.test.ActivityUnitTestCase<T extends android.app.Activity> |
This class provides isolated testing of a single activity. The activity under test will be created with minimal connection to the system infrastructure, and you can inject mocked or wrappered versions of many of Activity's dependencies. Most of the work is handled automatically here by setUp() and tearDown().
If you prefer a functional test, see ActivityInstrumentationTestCase.
It must be noted that, as a true unit test, your Activity will not be running in the normal system and will not participate in the normal interactions with other Activities. The following methods should not be called in this configuration - most of them will throw exceptions:
The following methods may be called but will not do anything. For test purposes, you can use the methods getStartedActivityIntent() and getStartedActivityRequest() to inspect the parameters that they were called with.
The following methods may be called but will not do anything. For test purposes, you can use the methods isFinishCalled() and getFinishedActivityRequest() to inspect the parameters that they were called with.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method will return the request code if the Activity under test called
finishActivity(int).
| |||||||||||
This method will return the value if your Activity under test calls
setRequestedOrientation(int).
| |||||||||||
This method will return the launch intent if your Activity under test calls
startActivity(Intent) or
startActivityForResult(Intent, int).
| |||||||||||
This method will return the launch request code if your Activity under test calls
startActivityForResult(Intent, int).
| |||||||||||
This method will notify you if the Activity under test called
finish(),
finishFromChild(Activity), or
finishActivity(int).
| |||||||||||
If you wish to inject a Mock, Isolated, or otherwise altered context, you can do so
here.
| |||||||||||
Set the application for use during the test.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Sets up the fixture, for example, open a network connection.
| |||||||||||
Start the activity under test, in the same way as if it was started by
Context.startActivity(), providing the
arguments it supplied.
| |||||||||||
Make sure all resources are cleaned up and garbage collected before moving on to the next
test.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class android.test.ActivityTestCase
| |||||||||||
From class android.test.InstrumentationTestCase
| |||||||||||
From class junit.framework.TestCase
| |||||||||||
From class junit.framework.Assert
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface junit.framework.Test
|
This method will return the request code if the Activity under test called finishActivity(int).
This method will return the value if your Activity under test calls setRequestedOrientation(int).
This method will return the launch intent if your Activity under test calls startActivity(Intent) or startActivityForResult(Intent, int).
This method will return the launch request code if your Activity under test calls startActivityForResult(Intent, int).
This method will notify you if the Activity under test called finish(), finishFromChild(Activity), or finishActivity(int).
If you wish to inject a Mock, Isolated, or otherwise altered context, you can do so here. You must call this function before calling startActivity(Intent, Bundle, Object). If you wish to obtain a real Context, as a building block, use getInstrumentation().getTargetContext().
Set the application for use during the test. You must call this function before calling startActivity(Intent, Bundle, Object). If your test does not call this method,
application | The Application object that will be injected into the Activity under test. |
---|
Sets up the fixture, for example, open a network connection. This method is called before a test is executed.
Exception |
---|
Start the activity under test, in the same way as if it was started by Context.startActivity(), providing the arguments it supplied. When you use this method to start the activity, it will automatically be stopped by tearDown().
This method will call onCreate(), but if you wish to further exercise Activity life cycle methods, you must call them yourself from your test case.
Do not call from your setUp() method. You must call this method from each of your test methods.
intent | The Intent as if supplied to startActivity(Intent). |
---|---|
savedInstanceState | The instance state, if you are simulating this part of the life cycle. Typically null. |
lastNonConfigurationInstance | This Object will be available to the Activity if it calls getLastNonConfigurationInstance(). Typically null. |
Make 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.
Exception |
---|