Aliases the current default Android JUnit 4 class runner, for future-proofing. If future versions
of JUnit change the default Runner class, they will also change the definition of this class.
Developers wanting to explicitly tag a class as an Android JUnit 4 class should use
@RunWith(AndroidJUnit4.class)
Used when executed with standard junit runner. Will attempt to delegate to
RobolectricTestRunner or delegate provided by android.junit.runner system property.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# AndroidJUnit4\n\nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \\| [\\[Expand All\\]](#) \n\nAndroidJUnit4\n=============\n\n| This package is part of the Android [support library](/topic/libraries/support-library) which is no longer maintained. The support library has been superseded by [AndroidX](/jetpack/androidx) which is part of [Jetpack](/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider [migrating](/jetpack/androidx/migrate) existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library [class\n| mappings](/jetpack/androidx/migrate/class-mappings).\n\n\n`\npublic\n\nfinal\n\nclass\nAndroidJUnit4\n`\n\n\n`\n\n\n`\n\n`\n\nextends Runner\n\n\n`\n\n`\n\n\nimplements\n\nFilterable,\n\nSortable\n\n\n`\n\n|---|---|-------------------------------------------|\n| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||\n| ↳ | org.junit.runner.Runner ||\n| | ↳ | android.support.test.runner.AndroidJUnit4 |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nAliases the current default Android JUnit 4 class runner, for future-proofing. If future versions\nof JUnit change the default Runner class, they will also change the definition of this class.\nDevelopers wanting to explicitly tag a class as an Android JUnit 4 class should use\n`@RunWith(AndroidJUnit4.class)`\n\nSummary\n-------\n\n| ### Public constructors ||\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[AndroidJUnit4](/reference/android/support/test/runner/AndroidJUnit4#AndroidJUnit4(java.lang.Class\u003c?\u003e, android.support.test.internal.util.AndroidRunnerParams))`(`[Class](https://developer.android.com/reference/java/lang/Class.html)`\u003c?\u003e klass, AndroidRunnerParams runnerParams) ` Constructs a new instance of the default runner |\n| ` `[AndroidJUnit4](/reference/android/support/test/runner/AndroidJUnit4#AndroidJUnit4(java.lang.Class\u003c?\u003e))`(`[Class](https://developer.android.com/reference/java/lang/Class.html)`\u003c?\u003e klass) ` Used when executed with standard junit runner. |\n\n| ### Public methods ||\n|----------------|-------------------------------------------------------------------------------------------------------------------------------------------|\n| ` void` | ` `[filter](/reference/android/support/test/runner/AndroidJUnit4#filter(org.junit.runner.manipulation.Filter))`(Filter filter) ` |\n| ` Description` | ` `[getDescription](/reference/android/support/test/runner/AndroidJUnit4#getDescription())`() ` |\n| ` void` | ` `[run](/reference/android/support/test/runner/AndroidJUnit4#run(org.junit.runner.notification.RunNotifier))`(RunNotifier runNotifier) ` |\n| ` void` | ` `[sort](/reference/android/support/test/runner/AndroidJUnit4#sort(org.junit.runner.manipulation.Sorter))`(Sorter sorter) ` |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` org.junit.runner.Runner ` |-------------------------|---------------------------| | ` abstract Description` | ` getDescription() ` | | ` abstract void` | ` run(RunNotifier arg0) ` | | ` int` | ` testCount() ` | ||\n| From class ` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html) | ` clone() ` | | ` boolean` | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void` | ` finalize() ` | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` `[String](https://developer.android.com/reference/java/lang/String.html) | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n| From interface ` org.junit.runner.Describable ` |-------------------------|----------------------| | ` abstract Description` | ` getDescription() ` | ||\n| From interface ` org.junit.runner.manipulation.Filterable ` |------------------|-------------------------| | ` abstract void` | ` filter(Filter arg0) ` | ||\n| From interface ` org.junit.runner.manipulation.Sortable ` |------------------|-----------------------| | ` abstract void` | ` sort(Sorter arg0) ` | ||\n\nPublic constructors\n-------------------\n\n### AndroidJUnit4\n\n```\nAndroidJUnit4 (Class\u003c?\u003e klass, \n AndroidRunnerParams runnerParams)\n```\n\nConstructs a new instance of the default runner\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|------------------------------|\n| `klass` | `Class` \u003cbr /\u003e |\n| `runnerParams` | `AndroidRunnerParams` \u003cbr /\u003e |\n\n| Throws ||\n|-----------------------|---|\n| `InitializationError` | |\n\n### AndroidJUnit4\n\n```\nAndroidJUnit4 (Class\u003c?\u003e klass)\n```\n\nUsed when executed with standard junit runner. Will attempt to delegate to\nRobolectricTestRunner or delegate provided by android.junit.runner system property.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------|----------------|\n| `klass` | `Class` \u003cbr /\u003e |\n\n| Throws ||\n|-----------------------|---|\n| `InitializationError` | |\n\nPublic methods\n--------------\n\n### filter\n\n```\nvoid filter (Filter filter)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|-----------------|\n| `filter` | `Filter` \u003cbr /\u003e |\n\n| Throws ||\n|--------------------------|---|\n| `NoTestsRemainException` | |\n\n### getDescription\n\n```\nDescription getDescription ()\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------------|--------|\n| `Description` | \u003cbr /\u003e |\n\n### run\n\n```\nvoid run (RunNotifier runNotifier)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------------|----------------------|\n| `runNotifier` | `RunNotifier` \u003cbr /\u003e |\n\n### sort\n\n```\nvoid sort (Sorter sorter)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|-----------------|\n| `sorter` | `Sorter` \u003cbr /\u003e |\n\n-\n\n Classes\n -------\n\n - [AndroidJUnit4](/reference/android/support/test/runner/AndroidJUnit4)\n - [AndroidJUnitRunner](/reference/android/support/test/runner/AndroidJUnitRunner)\n - [MonitoringInstrumentation](/reference/android/support/test/runner/MonitoringInstrumentation)\n - [MonitoringInstrumentation.ActivityFinisher](/reference/android/support/test/runner/MonitoringInstrumentation.ActivityFinisher)\n - [UsageTrackerFacilitator](/reference/android/support/test/runner/UsageTrackerFacilitator)"]]