public class Robolectric extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Robolectric.AttributeSetBuilder
Deprecated.
Use
AttributeSetBuilder instead. |
Constructor and Description |
---|
Robolectric() |
Modifier and Type | Method and Description |
---|---|
static <T extends Activity> |
buildActivity(Class<T> activityClass)
Creates a ActivityController for the given activity class.
|
static <T extends Activity> |
buildActivity(Class<T> activityClass,
Intent intent)
Creates a ActivityController for the given activity class with the intent.
|
static AttributeSetBuilder |
buildAttributeSet()
Allows for the programmatic creation of an
AttributeSet . |
static <T extends BackupAgent> |
buildBackupAgent(Class<T> backupAgentClass) |
static <T extends ContentProvider> |
buildContentProvider(Class<T> contentProviderClass) |
static <T extends Fragment> |
buildFragment(Class<T> fragmentClass)
Deprecated.
Native Fragments have been deprecated in Android P. Android encourages developers to use androidx fragments, to test these use FragmentScenario.
|
static <T extends Fragment> |
buildFragment(Class<T> fragmentClass,
Bundle arguments)
Deprecated.
Native Fragments have been deprecated in Android P. Android encourages developers to use androidx fragments, to test these use FragmentScenario.
|
static <T extends Fragment> |
buildFragment(Class<T> fragmentClass,
Class<? extends Activity> activityClass)
Deprecated.
Native Fragments have been deprecated in Android P. Android encourages developers to use androidx fragments, to test these use FragmentScenario.
|
static <T extends Fragment> |
buildFragment(Class<T> fragmentClass,
Class<? extends Activity> activityClass,
Bundle arguments)
Deprecated.
Native Fragments have been deprecated in Android P. Android encourages developers to use androidx fragments, to test these use FragmentScenario.
|
static <T extends Fragment> |
buildFragment(Class<T> fragmentClass,
Class<? extends Activity> activityClass,
Intent intent)
Deprecated.
Native Fragments have been deprecated in Android P. Android encourages developers to use androidx fragments, to test these use FragmentScenario.
|
static <T extends Fragment> |
buildFragment(Class<T> fragmentClass,
Class<? extends Activity> activityClass,
Intent intent,
Bundle arguments)
Deprecated.
Native Fragments have been deprecated in Android P. Android encourages developers to use androidx fragments, to test these use FragmentScenario.
|
static <T extends Fragment> |
buildFragment(Class<T> fragmentClass,
Intent intent)
Deprecated.
Native Fragments have been deprecated in Android P. Android encourages developers to use androidx fragments, to test these use FragmentScenario.
|
static <T extends Fragment> |
buildFragment(Class<T> fragmentClass,
Intent intent,
Bundle arguments)
Deprecated.
Native Fragments have been deprecated in Android P. Android encourages developers to use androidx fragments, to test these use FragmentScenario.
|
static <T extends IntentService> |
buildIntentService(Class<T> serviceClass) |
static <T extends IntentService> |
buildIntentService(Class<T> serviceClass,
Intent intent) |
static <T extends Service> |
buildService(Class<T> serviceClass) |
static <T extends Service> |
buildService(Class<T> serviceClass,
Intent intent) |
static void |
flushBackgroundThreadScheduler()
Execute all runnables that have been enqueued on the background scheduler.
|
static void |
flushForegroundThreadScheduler()
Execute all runnables that have been enqueued on the foreground scheduler.
|
static Scheduler |
getBackgroundThreadScheduler()
Return the background scheduler.
|
static Scheduler |
getForegroundThreadScheduler()
Return the foreground scheduler (e.g.
|
static <T extends Activity> |
setupActivity(Class<T> activityClass)
Deprecated.
use
androidx.test.core.app.ActivityScenario |
static <T extends BackupAgent> |
setupBackupAgent(Class<T> backupAgentClass) |
static <T extends ContentProvider> |
setupContentProvider(Class<T> contentProviderClass) |
static <T extends ContentProvider> |
setupContentProvider(Class<T> contentProviderClass,
String authority) |
static <T extends IntentService> |
setupIntentService(Class<T> serviceClass) |
static <T extends Service> |
setupService(Class<T> serviceClass) |
public static <T extends Service> ServiceController<T> buildService(Class<T> serviceClass)
public static <T extends Service> ServiceController<T> buildService(Class<T> serviceClass, Intent intent)
public static <T extends IntentService> IntentServiceController<T> buildIntentService(Class<T> serviceClass)
public static <T extends IntentService> IntentServiceController<T> buildIntentService(Class<T> serviceClass, Intent intent)
public static <T extends IntentService> T setupIntentService(Class<T> serviceClass)
public static <T extends ContentProvider> ContentProviderController<T> buildContentProvider(Class<T> contentProviderClass)
public static <T extends ContentProvider> T setupContentProvider(Class<T> contentProviderClass)
public static <T extends ContentProvider> T setupContentProvider(Class<T> contentProviderClass, String authority)
public static <T extends Activity> ActivityController<T> buildActivity(Class<T> activityClass)
Creates a ActivityController for the given activity class.
Consider using androidx.test.core.app.ActivityScenario
instead, which provides higher-level, streamlined APIs to control the lifecycle and it works with instrumentation tests too.
public static <T extends Activity> ActivityController<T> buildActivity(Class<T> activityClass, Intent intent)
Creates a ActivityController for the given activity class with the intent.
Note: the activity class is not determined by the intent.
Consider using androidx.test.core.app.ActivityScenario
instead, which provides higher-level, streamlined APIs to control the lifecycle and it works with instrumentation tests too.
@Deprecated public static <T extends Activity> T setupActivity(Class<T> activityClass)
androidx.test.core.app.ActivityScenario
Simulates starting activity with the given class type and returns its reference.
Use androidx.test.core.app.ActivityScenario
instead, which works with instrumentation tests too.
@Deprecated public static <T extends Fragment> FragmentController<T> buildFragment(Class<T> fragmentClass)
Creates a FragmentController for the given fragment class.
FragmentController provides low-level APIs to control its lifecycle. Please consider using androidx.fragment.app.testing.FragmentScenario
instead, which provides higher level APIs and works with instrumentation tests too.
@Deprecated public static <T extends Fragment> FragmentController<T> buildFragment(Class<T> fragmentClass, Bundle arguments)
Creates a FragmentController for the given fragment class with the arguments.
FragmentController provides low-level APIs to control its lifecycle. Please consider using androidx.fragment.app.testing.FragmentScenario
instead, which provides higher level APIs and works with instrumentation tests too.
@Deprecated public static <T extends Fragment> FragmentController<T> buildFragment(Class<T> fragmentClass, Class<? extends Activity> activityClass)
Creates a FragmentController for the given fragment class in the specified host activity.
In general, it’s a bad practice to design a fragment having dependency to a specific activity. Consider removing the dependency and use other buildFragment(java.lang.Class<T>)
method or androidx.fragment.app.testing.FragmentScenario
.
FragmentController provides low-level APIs to control its lifecycle. Please consider using androidx.fragment.app.testing.FragmentScenario
instead, which provides higher level APIs and works with instrumentation tests too.
@Deprecated public static <T extends Fragment> FragmentController<T> buildFragment(Class<T> fragmentClass, Intent intent)
Creates a FragmentController for the given fragment class. The given intent is set to the host activity.
Note: the host activity class is not determined by the intent.
FragmentController provides low-level APIs to control its lifecycle. Please consider using androidx.fragment.app.testing.FragmentScenario
instead, which provides higher level APIs and works with instrumentation tests too.
@Deprecated public static <T extends Fragment> FragmentController<T> buildFragment(Class<T> fragmentClass, Intent intent, Bundle arguments)
Creates a FragmentController for the given fragment class with the arguments. The given intent is set to the host activity.
Note: the host activity class is not determined by the intent.
FragmentController provides low-level APIs to control its lifecycle. Please consider using androidx.fragment.app.testing.FragmentScenario
instead, which provides higher level APIs and works with instrumentation tests too.
@Deprecated public static <T extends Fragment> FragmentController<T> buildFragment(Class<T> fragmentClass, Class<? extends Activity> activityClass, Intent intent)
Creates a FragmentController for the given fragment class in the specified host activity. The given intent is set to the host activity.
Note: the host activity class is not determined by the intent.
In general, it’s a bad practice to design a fragment having dependency to a specific activity. Consider removing the dependency and use other buildFragment(java.lang.Class<T>)
method or androidx.fragment.app.testing.FragmentScenario
.
FragmentController provides low-level APIs to control its lifecycle. Please consider using androidx.fragment.app.testing.FragmentScenario
instead, which provides higher level APIs and works with instrumentation tests too.
@Deprecated public static <T extends Fragment> FragmentController<T> buildFragment(Class<T> fragmentClass, Class<? extends Activity> activityClass, Bundle arguments)
Creates a FragmentController for the given fragment class in the specified host activity with the arguments.
In general, it’s a bad practice to design a fragment having dependency to a specific activity. Consider removing the dependency and use other buildFragment(java.lang.Class<T>)
method or androidx.fragment.app.testing.FragmentScenario
.
FragmentController provides low-level APIs to control its lifecycle. Please consider using androidx.fragment.app.testing.FragmentScenario
instead, which provides higher level APIs and works with instrumentation tests too.
@Deprecated public static <T extends Fragment> FragmentController<T> buildFragment(Class<T> fragmentClass, Class<? extends Activity> activityClass, Intent intent, Bundle arguments)
Creates a FragmentController for the given fragment class in the specified host activity with the arguments. The given intent is set to the host activity.
Note: the host activity class is not determined by the intent.
In general, it’s a bad practice to design a fragment having dependency to a specific activity. Consider removing the dependency and use other buildFragment(java.lang.Class<T>)
method or androidx.fragment.app.testing.FragmentScenario
.
FragmentController provides low-level APIs to control its lifecycle. Please consider using androidx.fragment.app.testing.FragmentScenario
instead, which provides higher level APIs and works with instrumentation tests too.
public static <T extends BackupAgent> BackupAgentController<T> buildBackupAgent(Class<T> backupAgentClass)
public static <T extends BackupAgent> T setupBackupAgent(Class<T> backupAgentClass)
public static AttributeSetBuilder buildAttributeSet()
Allows for the programmatic creation of an AttributeSet
.
Useful for testing View
classes without the need for creating XML snippets.
public static Scheduler getForegroundThreadScheduler()
Return the foreground scheduler (e.g. the UI thread scheduler).
public static void flushForegroundThreadScheduler()
Execute all runnables that have been enqueued on the foreground scheduler.
public static Scheduler getBackgroundThreadScheduler()
Return the background scheduler.
public static void flushBackgroundThreadScheduler()
Execute all runnables that have been enqueued on the background scheduler.