# AppComponentFactoryRule

Artifact: [androidx.test.ext:junit](https://developer.android.com/jetpack/androidx/releases/test-ext) [View Source](https://cs.android.com/search?q=file:androidx/test/ext/junit/rules/AppComponentFactoryRule.kt+class:androidx.test.ext.junit.rules.AppComponentFactoryRule)

*** ** * ** ***

<br />

```
class AppComponentFactoryRule : ExternalResource
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [org.junit.rules.ExternalResource](https://junit.org/junit4/javadoc/latest/org/junit/rules/ExternalResource.html) ||
|   | ↳ | [androidx.test.ext.junit.rules.AppComponentFactoryRule](https://developer.android.com/reference/kotlin/androidx/test/ext/junit/rules/AppComponentFactoryRule) |

*** ** * ** ***

JUnit `https://junit.org/junit4/javadoc/latest/org/junit/Rule.html` that let you define a `https://developer.android.com/reference/android/app/AppComponentFactory.html` before the tests starts and clean-up the factory after the test.

This rule is designed to be used with `https://developer.android.com/reference/kotlin/androidx/test/ext/junit/rules/ActivityScenarioRule`.

Example:

```kotlin
// We use `order`  to to ensure the `AppComponentFactoryRule` will always run BEFORE the
// `ActivityScenarioRule` so that your custom `AppComponentFactory` is available when the
// activity is launched.
@get:Rule(order = 1)
val factoryRule = AppComponentFactoryRule(MyAppComponentFactory())

@get:Rule(order = 2)
val activityRule = ActivityScenarioRule<MyActivity>()
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/test/ext/junit/rules/AppComponentFactoryRule#AppComponentFactoryRule(android.app.AppComponentFactory)(factory: https://developer.android.com/reference/android/app/AppComponentFactory.html)` |

| ### Protected functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/ext/junit/rules/AppComponentFactoryRule#after()()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/ext/junit/rules/AppComponentFactoryRule#before()()` |

### Inherited functions

From [org.junit.rules.ExternalResource](https://junit.org/junit4/javadoc/latest/org/junit/rules/ExternalResource.html) `https://junit.org/junit4/javadoc/latest/org/junit/runners/model/Statement.html` `https://junit.org/junit4/javadoc/latest/org/junit/rules/ExternalResource.html#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)`

## Public constructors

### AppComponentFactoryRule

```
AppComponentFactoryRule(factory: AppComponentFactory)
```

## Protected functions

### after

```
protected open fun after(): Unit
```

### before

```
protected open fun before(): Unit
```