Stay organized with collections Save and categorize content based on your preferences.

UiThreadTestRule

public class UiThreadTestRule


This rule allows the test method annotated with UiThreadTest to execute on the application's main thread (or UI thread).

Note, methods annotated with Before and After will also be executed on the UI thread.

See also
UiThreadTest

if you need to switch in and out of the UI thread within your method.

Summary

Public constructors

Public methods

Statement
apply(Statement base, Description description)
void

Helper method for running part of a method on the UI thread.

Public constructors

UiThreadTestRule

public UiThreadTestRule()

Public methods

apply

public Statement apply(Statement base, Description description)

runOnUiThread

public void runOnUiThread(Runnable runnable)

Helper method for running part of a method on the UI thread.

Note: In most cases it is simpler to annotate the test method with UiThreadTest.

Use this method if you need to switch in and out of the UI thread within your method.

Parameters
Runnable runnable

runnable containing test code in the Runnable#run() method

Throws
java.lang.Throwable java.lang.Throwable
See also
UiThreadTest