# AndroidJUnit4

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/runners/AndroidJUnit4.java+class:androidx.test.ext.junit.runners.AndroidJUnit4)

*** ** * ** ***


```
public final class AndroidJUnit4 extends Runner implements Filterable, Sortable
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [org.junit.runner.Runner](https://junit.org/junit4/javadoc/latest/org/junit/runner/Runner.html) ||
|   | ↳ | [androidx.test.ext.junit.runners.AndroidJUnit4](https://developer.android.com/reference/androidx/test/ext/junit/runners/AndroidJUnit4) |

*** ** * ** ***

A JUnit4 runner for Android tests.

This runner offers several features on top of the standard JUnit4 runner,

- Supports running on Robolectric. This implementation will delegate to RobolectricTestRunner if test is running in Robolectric environment. A custom runner can be provided by specifying the full class name in a 'android.junit.runner' system property.
- Supports a per-test timeout - specified via a 'timeout_msec' `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner` argument.
- Supports running tests on the application's UI Thread, for tests annotated with `https://developer.android.com/reference/androidx/test/annotation/UiThreadTest`.

Usage `@RunWith(AndroidJUnit4.class)`

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/test/ext/junit/runners/AndroidJUnit4#AndroidJUnit4(java.lang.Class<?>)(https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> klass)` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/test/ext/junit/runners/AndroidJUnit4#filter(org.junit.runner.manipulation.Filter)(https://junit.org/junit4/javadoc/latest/org/junit/runner/manipulation/Filter.html filter)` |
| `https://junit.org/junit4/javadoc/latest/org/junit/runner/Description.html` | `https://developer.android.com/reference/androidx/test/ext/junit/runners/AndroidJUnit4#getDescription()()` |
| `void` | `https://developer.android.com/reference/androidx/test/ext/junit/runners/AndroidJUnit4#run(org.junit.runner.notification.RunNotifier)(https://junit.org/junit4/javadoc/latest/org/junit/runner/notification/RunNotifier.html runNotifier)` |
| `void` | `https://developer.android.com/reference/androidx/test/ext/junit/runners/AndroidJUnit4#sort(org.junit.runner.manipulation.Sorter)(https://junit.org/junit4/javadoc/latest/org/junit/runner/manipulation/Sorter.html sorter)` |

### Inherited methods

From [org.junit.runner.Runner](https://junit.org/junit4/javadoc/latest/org/junit/runner/Runner.html) `int` `https://junit.org/junit4/javadoc/latest/org/junit/runner/Runner.html#testCount--()`

## Public constructors

### AndroidJUnit4

```
public AndroidJUnit4(Class<@NonNull ?> klass)
```

## Public methods

### filter

```
public void filter(Filter filter)
```

| Throws |
|---|---|
| `https://junit.org/junit4/javadoc/latest/org/junit/runner/manipulation/NoTestsRemainException.html` |   |

### getDescription

```
public Description getDescription()
```

### run

```
public void run(RunNotifier runNotifier)
```

### sort

```
public void sort(Sorter sorter)
```