@Deprecated public abstract class ActivityInstrumentationTestCase2<T extends Activity> extends ActivityTestCase
Other options supported by this test case include:
UiThreadTest
).setActivityIntent(Intent)
).This class replaces ActivityInstrumentationTestCase
, which is deprecated.
New tests should be written using this base class.
If you prefer an isolated unit test, see ActivityUnitTestCase
.
Constructor and Description |
---|
ActivityInstrumentationTestCase2(Class<T> activityClass)
Deprecated.
Creates an
ActivityInstrumentationTestCase2 . |
ActivityInstrumentationTestCase2(String pkg,
Class<T> activityClass)
Deprecated.
use
ActivityInstrumentationTestCase2(Class) instead |
Modifier and Type | Method and Description |
---|---|
T |
getActivity()
Deprecated.
Get the Activity under test, starting it if necessary.
|
protected void |
runTest()
Deprecated.
Runs the current unit test.
|
void |
setActivityInitialTouchMode(boolean initialTouchMode)
Deprecated.
Call this method before the first call to
getActivity() to set the initial touch
mode for the Activity under test. |
void |
setActivityIntent(Intent i)
Deprecated.
Call this method before the first call to
getActivity() to inject a customized Intent
into the Activity under test. |
protected void |
setUp()
Deprecated.
|
protected void |
tearDown()
Deprecated.
Make sure all resources are cleaned up and garbage collected before moving on to the next
test.
|
scrubClass, setActivity
getInstrumentation, injectInsrumentation, injectInstrumentation, launchActivity, launchActivityWithIntent, runTestOnUiThread, sendKeys, sendKeys, sendRepeatedKeys
@Deprecated public ActivityInstrumentationTestCase2(String pkg, Class<T> activityClass)
ActivityInstrumentationTestCase2(Class)
insteadActivityInstrumentationTestCase2
.pkg
- ignored - no longer in use.activityClass
- The activity to test. This must be a class in the instrumentation
targetPackage specified in the AndroidManifest.xmlpublic ActivityInstrumentationTestCase2(Class<T> activityClass)
ActivityInstrumentationTestCase2
.activityClass
- The activity to test. This must be a class in the instrumentation
targetPackage specified in the AndroidManifest.xmlpublic T getActivity()
If you wish to provide custom setup values to your Activity, you may call
setActivityIntent(Intent)
and/or setActivityInitialTouchMode(boolean)
before your first call to getActivity(). Calling them after your Activity has
started will have no effect.
NOTE: Activities under test may not be started from within the UI thread.
If your test method is annotated with UiThreadTest
, then your Activity
will be started automatically just before your test method is run. You still call this
method in order to get the Activity under test.
getActivity
in class ActivityTestCase
public void setActivityIntent(Intent i)
getActivity()
to inject a customized Intent
into the Activity under test.
If you do not call this, the default intent will be provided. If you call this after your Activity has been started, it will have no effect.
NOTE: Activities under test may not be started from within the UI thread.
If your test method is annotated with UiThreadTest
, then you must call
setActivityIntent(Intent)
from setUp()
.
The default Intent (if this method is not called) is:
action = Intent.ACTION_MAIN
flags = Intent.FLAG_ACTIVITY_NEW_TASK
All other fields are null or empty.
i
- The Intent to start the Activity with, or null to reset to the default Intent.public void setActivityInitialTouchMode(boolean initialTouchMode)
getActivity()
to set the initial touch
mode for the Activity under test.
If you do not call this, the touch mode will be false. If you call this after your Activity has been started, it will have no effect.
NOTE: Activities under test may not be started from within the UI thread.
If your test method is annotated with UiThreadTest
, then you must call
setActivityInitialTouchMode(boolean)
from setUp()
.
initialTouchMode
- true if the Activity should be placed into "touch mode" when startedprotected void tearDown() throws Exception
InstrumentationTestCase
tearDown
in class InstrumentationTestCase
Exception
protected void runTest() throws Throwable
UiThreadTest
, force the Activity to be created before switching to
the UI thread.runTest
in class InstrumentationTestCase
Throwable