# 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)

*** ** * ** ***


```
class IntentsTestRule<T : Activity?> : ActivityTestRule<T!>
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.test.rule.ActivityTestRule](https://developer.android.com/reference/kotlin/androidx/test/rule/ActivityTestRule)\<T!\> ||
|   | ↳ | [androidx.test.espresso.intent.rule.IntentsTestRule](https://developer.android.com/reference/kotlin/androidx/test/espresso/intent/rule/IntentsTestRule) |

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> Use `https://developer.android.com/reference/kotlin/androidx/test/espresso/intent/rule/IntentsRule`, and if necessary in conjunction with `https://developer.android.com/reference/kotlin/androidx/test/core/app/ActivityScenario` or `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/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 : https://developer.android.com/reference/android/app/Activity.html?>` | The activity to test |

## Summary

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

| ### Protected functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[afterActivityFinished](https://developer.android.com/reference/kotlin/androidx/test/espresso/intent/rule/IntentsTestRule#afterActivityFinished())()` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[afterActivityLaunched](https://developer.android.com/reference/kotlin/androidx/test/espresso/intent/rule/IntentsTestRule#afterActivityLaunched())()` **This function is deprecated.** Deprecated in Java |

### Inherited functions

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

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[beforeActivityLaunched](https://developer.android.com/reference/kotlin/androidx/test/rule/ActivityTestRule#beforeActivityLaunched())()`

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[finishActivity](https://developer.android.com/reference/kotlin/androidx/test/rule/ActivityTestRule#finishActivity())()`

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

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

**This function is deprecated.** Deprecated in Java
`T!` `[launchActivity](https://developer.android.com/reference/kotlin/androidx/test/rule/ActivityTestRule#launchActivity(android.content.Intent))(startIntent: https://developer.android.com/reference/android/content/Intent.html?)`

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[runOnUiThread](https://developer.android.com/reference/kotlin/androidx/test/rule/ActivityTestRule#runOnUiThread(java.lang.Runnable))(runnable: https://developer.android.com/reference/java/lang/Runnable.html!)`

**This function 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-)(p: https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html!, p1: https://junit.org/junit4/javadoc/latest/org/junit/runner/Description.html!)`

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

### Inherited properties

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

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

## Public constructors

### IntentsTestRule

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

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

### IntentsTestRule

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

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

### IntentsTestRule

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

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

## Protected functions

### afterActivityFinished

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

> [!CAUTION]
> **This function 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 fun [afterActivityLaunched](https://developer.android.com/reference/kotlin/androidx/test/espresso/intent/rule/IntentsTestRule#afterActivityLaunched())(): Unit
```

> [!CAUTION]
> **This function 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.