# IntentsTestRule

Artifact: [androidx.test.espresso:espresso-intents](https://developer.android.com/jetpack/androidx/releases/test-espresso) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/intent/rule/IntentsTestRule.java+class:androidx.test.espresso.intent.rule.IntentsTestRule)

*** ** * ** ***


```
public class IntentsTestRule<T extends Activity> extends ActivityTestRule<T>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.test.rule.ActivityTestRule](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule)\<T\> ||
|   | ↳ | [androidx.test.espresso.intent.rule.IntentsTestRule](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule) |

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsRule`, and if necessary in conjunction with `https://developer.android.com/reference/androidx/test/core/app/ActivityScenario` or `https://developer.android.com/reference/androidx/test/ext/junit/rules/ActivityScenarioRule` instead.

This rule makes it easy to use Espresso-Intents APIs in functional UI tests. This class is an extension of `https://developer.android.com/reference/androidx/test/rule/ActivityTestRule`, which initializes Espresso-Intents before each test annotated with `https://junit.org/junit4/javadoc/latest/org/junit/Test.html` and releases Espresso-Intents after each test run. The Activity will be terminated after each test and this rule can be used in the same way as `https://developer.android.com/reference/androidx/test/rule/ActivityTestRule`.

Espresso-Intents APIs can be used in two ways:

- Intent Verification, using the intended API
- Intent Stubbing, using the intending API

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/android/app/Activity.html>` | The activity to test |

## Summary

| ### Public constructors |
|---|
| `[IntentsTestRule](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#IntentsTestRule(java.lang.Class<T>))(https://developer.android.com/reference/java/lang/Class.html<T> activityClass)` **This method is deprecated.** Deprecated in Java |
| `[IntentsTestRule](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#IntentsTestRule(java.lang.Class<T>,boolean))(https://developer.android.com/reference/java/lang/Class.html<T> activityClass, boolean initialTouchMode)` **This method is deprecated.** Deprecated in Java |
| `[IntentsTestRule](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#IntentsTestRule(java.lang.Class<T>,boolean,boolean))( https://developer.android.com/reference/java/lang/Class.html<T> activityClass, boolean initialTouchMode, boolean launchActivity )` **This method is deprecated.** Deprecated in Java |

| ### Protected methods |
|---|---|
| `void` | `[afterActivityFinished](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#afterActivityFinished())()` **This method is deprecated.** Deprecated in Java |
| `void` | `[afterActivityLaunched](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#afterActivityLaunched())()` **This method is deprecated.** Deprecated in Java |

### Inherited fields

From [androidx.test.rule.ActivityTestRule](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule) `volatile https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/androidx/test/rule/ActivityTestRule#activityResult()`

**This field is deprecated.** Deprecated in Java

### Inherited methods

From [androidx.test.rule.ActivityTestRule](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule) `https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html` `[apply](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule#apply(org.junit.runners.model.Statement,org.junit.runner.Description))(https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html base, https://junit.org/junit4/javadoc/latest/org/junit/runner/Description.html description)`

**This method is deprecated.** Deprecated in Java
`void` `[beforeActivityLaunched](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule#beforeActivityLaunched())()`

**This method is deprecated.** Deprecated in Java
`void` `[finishActivity](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule#finishActivity())()`

**This method is deprecated.** Deprecated in Java
`T` `[getActivity](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule#getActivity())()`

**This method is deprecated.** Deprecated in Java
`https://developer.android.com/reference/android/content/Intent.html` `[getActivityIntent](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule#getActivityIntent())()`

**This method is deprecated.** Deprecated in Java
`https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `[getActivityResult](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule#getActivityResult())()`

**This method is deprecated.** Deprecated in Java
`T` `[launchActivity](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule#launchActivity(android.content.Intent))(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/content/Intent.html startIntent)`

**This method is deprecated.** Deprecated in Java
`void` `[runOnUiThread](https://developer.android.com/reference/androidx/test/rule/ActivityTestRule#runOnUiThread(java.lang.Runnable))(https://developer.android.com/reference/java/lang/Runnable.html runnable)`

**This method is deprecated.** Deprecated in Java
From [org.junit.rules.TestRule](https://junit.org/junit4/javadoc/latest/org/junit/rules/TestRule.html) `abstract https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html` `[apply](https://junit.org/junit4/javadoc/latest/org/junit/rules/TestRule.html#apply-org.junit.runners.model.Statement-org.junit.runner.Description-)(https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html p, https://junit.org/junit4/javadoc/latest/org/junit/runner/Description.html p1)`

**This method is deprecated.** Deprecated in Java

## Public constructors

### IntentsTestRule

```
public [IntentsTestRule](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#IntentsTestRule(java.lang.Class<T>))(Class<T> activityClass)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

### IntentsTestRule

```
public [IntentsTestRule](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#IntentsTestRule(java.lang.Class<T>,boolean))(Class<T> activityClass, boolean initialTouchMode)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

### IntentsTestRule

```
public [IntentsTestRule](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#IntentsTestRule(java.lang.Class<T>,boolean,boolean))(
    Class<T> activityClass,
    boolean initialTouchMode,
    boolean launchActivity
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

## Protected methods

### afterActivityFinished

```
protected void [afterActivityFinished](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#afterActivityFinished())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Override this method to execute any code that should run after the currently launched `https://developer.android.com/reference/android/app/Activity.html` is finished. This method is called after each test method, including any method annotated with `https://junit.org/junit4/javadoc/latest/org/junit/After.html`.

Prefer `https://junit.org/junit4/javadoc/latest/org/junit/After.html` over this method. This method should usually not be overwritten directly in tests and only be used by subclasses of ActivityTestRule to get notified when the activity is created and visible but test runs.

### afterActivityLaunched

```
protected void [afterActivityLaunched](https://developer.android.com/reference/androidx/test/espresso/intent/rule/IntentsTestRule#afterActivityLaunched())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Override this method to execute any code that should run after your `https://developer.android.com/reference/android/app/Activity.html` is launched, but before any test code is run including any method annotated with `https://junit.org/junit4/javadoc/latest/org/junit/Before.html`.

Prefer `https://junit.org/junit4/javadoc/latest/org/junit/Before.html` over this method. This method should usually not be overwritten directly in tests and only be used by subclasses of ActivityTestRule to get notified when the activity is created and visible but test runs.