# ActivityTestCase

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/test/ActivityTestCase#pubctors)\|[Protected Methods](https://developer.android.com/reference/android/test/ActivityTestCase#promethods)\|[Inherited Methods](https://developer.android.com/reference/android/test/ActivityTestCase#inhmethods)  

# ActivityTestCase

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/test/ActivityTestCase "View this page in Kotlin")\|Java

`
public


abstract
class
ActivityTestCase
`  
`


``

extends `[InstrumentationTestCase](https://developer.android.com/reference/android/test/InstrumentationTestCase)`


``


`

|---|---|-------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [android.test.InstrumentationTestCase](https://developer.android.com/reference/android/test/InstrumentationTestCase) ||
|   | ↳ | android.test.ActivityTestCase |

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known direct subclasses [ActivityInstrumentationTestCase](https://developer.android.com/reference/android/test/ActivityInstrumentationTestCase)\<T extends[Activity](https://developer.android.com/reference/android/app/Activity)\>,[ActivityInstrumentationTestCase2](https://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2)\<T extends[Activity](https://developer.android.com/reference/android/app/Activity)\>,[ActivityUnitTestCase](https://developer.android.com/reference/android/test/ActivityUnitTestCase)\<T extends[Activity](https://developer.android.com/reference/android/app/Activity)\> |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [ActivityInstrumentationTestCase](https://developer.android.com/reference/android/test/ActivityInstrumentationTestCase)\<T extends[Activity](https://developer.android.com/reference/android/app/Activity)\>   | *This class was deprecated in API level 3. new tests should be written using[ActivityInstrumentationTestCase2](https://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2), which provides more options for configuring the Activity under test*                         | | [ActivityInstrumentationTestCase2](https://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2)\<T extends[Activity](https://developer.android.com/reference/android/app/Activity)\> | *This class was deprecated in API level 24. Use[ActivityTestRule](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule)instead. New tests should be written using the[Android Testing Support Library](https://developer.android.com/tools/testing-support-library).* | | [ActivityUnitTestCase](https://developer.android.com/reference/android/test/ActivityUnitTestCase)\<T extends[Activity](https://developer.android.com/reference/android/app/Activity)\>                         | *This class was deprecated in API level 24. Write[Local Unit Tests](https://developer.android.com/training/testing/unit-testing/local-unit-tests)instead.*                                                                                                                                          | |

<br />

*** ** * ** ***

<br />

**This class was deprecated in API level 24.**   
New tests should be written using the[Android Testing Support Library](https://developer.android.com/tools/testing-support-library).

This is common code used to support Activity test cases. For more useful classes, please see[ActivityUnitTestCase](https://developer.android.com/reference/android/test/ActivityUnitTestCase)and[ActivityInstrumentationTestCase](https://developer.android.com/reference/android/test/ActivityInstrumentationTestCase).

## Summary

|                                                 ### Public constructors                                                 ||
|----------------------------------------------------------------------------------------------------------------------|---|
| ` `[ActivityTestCase](https://developer.android.com/reference/android/test/ActivityTestCase#ActivityTestCase())`() ` |

|                                                                                                                                                                                                 ### Protected methods                                                                                                                                                                                                  ||
|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[Activity](https://developer.android.com/reference/android/app/Activity) | ` `[getActivity](https://developer.android.com/reference/android/test/ActivityTestCase#getActivity())`() `                                                                                                                                                                                                                                |
| ` void`                                                                     | ` `[scrubClass](https://developer.android.com/reference/android/test/ActivityTestCase#scrubClass(java.lang.Class<?>))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> testCaseClass) ` This function is called by various TestCase implementations, at tearDown() time, in order to scrub out any class variables. |
| ` void`                                                                     | ` `[setActivity](https://developer.android.com/reference/android/test/ActivityTestCase#setActivity(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` testActivity) ` Set the activity under test.                                                                                        |

| ### Inherited methods |
|-----------------------|---|
| From class` `[android.test.InstrumentationTestCase](https://developer.android.com/reference/android/test/InstrumentationTestCase)` ` |---------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation)         | ` `[getInstrumentation](https://developer.android.com/reference/android/test/InstrumentationTestCase#getInstrumentation())`() ` Inheritors can access the instrumentation using this.                                                                                                                                                                                                                                                                                                                                                     | | ` void`                                                                                           | ` `[injectInsrumentation](https://developer.android.com/reference/android/test/InstrumentationTestCase#injectInsrumentation(android.app.Instrumentation))`(`[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation)` instrumentation) ` *This method was deprecated in API level 15. Incorrect spelling, use[injectInstrumentation(android.app.Instrumentation)](https://developer.android.com/reference/android/test/InstrumentationTestCase#injectInstrumentation(android.app.Instrumentation))instead.* | | ` void`                                                                                           | ` `[injectInstrumentation](https://developer.android.com/reference/android/test/InstrumentationTestCase#injectInstrumentation(android.app.Instrumentation))`(`[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation)` instrumentation) ` Injects instrumentation into this test case.                                                                                                                                                                                                                     | | ` final <T extends `[Activity](https://developer.android.com/reference/android/app/Activity)`> T` | ` `[launchActivity](https://developer.android.com/reference/android/test/InstrumentationTestCase#launchActivity(java.lang.String,%20java.lang.Class<T>,%20android.os.Bundle))`(`[String](https://developer.android.com/reference/java/lang/String)` pkg, `[Class](https://developer.android.com/reference/java/lang/Class)`<T> activityCls, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` extras) ` Utility method for launching an activity.                                                                     | | ` final <T extends `[Activity](https://developer.android.com/reference/android/app/Activity)`> T` | ` `[launchActivityWithIntent](https://developer.android.com/reference/android/test/InstrumentationTestCase#launchActivityWithIntent(java.lang.String,%20java.lang.Class<T>,%20android.content.Intent))`(`[String](https://developer.android.com/reference/java/lang/String)` pkg, `[Class](https://developer.android.com/reference/java/lang/Class)`<T> activityCls, `[Intent](https://developer.android.com/reference/android/content/Intent)` intent) ` Utility method for launching an activity with a specific Intent.                | | ` void`                                                                                           | ` `[runTest](https://developer.android.com/reference/android/test/InstrumentationTestCase#runTest())`() ` Runs the current unit test.                                                                                                                                                                                                                                                                                                                                                                                                     | | ` void`                                                                                           | ` `[runTestOnUiThread](https://developer.android.com/reference/android/test/InstrumentationTestCase#runTestOnUiThread(java.lang.Runnable))`(`[Runnable](https://developer.android.com/reference/java/lang/Runnable)` r) ` Helper for running portions of a test on the UI thread.                                                                                                                                                                                                                                                         | | ` void`                                                                                           | ` `[sendKeys](https://developer.android.com/reference/android/test/InstrumentationTestCase#sendKeys(int[]))`(int... keys) ` Sends a series of key events through instrumentation and waits for idle.                                                                                                                                                                                                                                                                                                                                      | | ` void`                                                                                           | ` `[sendKeys](https://developer.android.com/reference/android/test/InstrumentationTestCase#sendKeys(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` keysSequence) ` Sends a series of key events through instrumentation and waits for idle.                                                                                                                                                                                                                                                     | | ` void`                                                                                           | ` `[sendRepeatedKeys](https://developer.android.com/reference/android/test/InstrumentationTestCase#sendRepeatedKeys(int[]))`(int... keys) ` Sends a series of key events through instrumentation and waits for idle.                                                                                                                                                                                                                                                                                                                      | | ` void`                                                                                           | ` `[tearDown](https://developer.android.com/reference/android/test/InstrumentationTestCase#tearDown())`() ` Make sure all resources are cleaned up and garbage collected before moving on to the next test.                                                                                                                                                                                                                                                                                                                               | ||
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### ActivityTestCase

```
public ActivityTestCase ()
```

<br />

<br />

## Protected methods

### getActivity

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected Activity getActivity ()
```

<br />

<br />

|                                                      Returns                                                      ||
|--------------------------------------------------------------------------|-----------------------------------------|
| [Activity](https://developer.android.com/reference/android/app/Activity) | Returns the activity under test. <br /> |

### scrubClass

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected void scrubClass (Class<?> testCaseClass)
```

This function is called by various TestCase implementations, at tearDown() time, in order to scrub out any class variables. This protects against memory leaks in the case where a test case creates a non-static inner class (thus referencing the test case) and gives it to someone else to hold onto.

<br />

|                                     Parameters                                     ||
|-----------------|-------------------------------------------------------------------|
| `testCaseClass` | `Class`: The class of the derived TestCase implementation. <br /> |

|                                                                Throws                                                                ||
|----------------------------------------------------------------------------------------------------|----------------------------------|
|                                                                                                    | java.lang.IllegalAccessException |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) |                                  |

### setActivity

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected void setActivity (Activity testActivity)
```

Set the activity under test.

<br />

|                         Parameters                         ||
|----------------|--------------------------------------------|
| `testActivity` | `Activity`: The activity under test <br /> |