# UiThreadTest

Artifact: [androidx.test:rules](https://developer.android.com/jetpack/androidx/releases/test) [View Source](https://cs.android.com/search?q=file:androidx/test/annotation/UiThreadTest.java+class:androidx.test.annotation.UiThreadTest)

*** ** * ** ***


```
@Target(value = [ElementType.METHOD, ElementType.TYPE])
@Retention(value = RetentionPolicy.RUNTIME)
public annotation UiThreadTest
```

<br />

*** ** * ** ***

Classes and methods annotated with this annotation will be executed on the application's UI thread (or main thread).

This annotation will only take effect for `https://junit.org/junit4/javadoc/latest/org/junit/Test.html`, `https://junit.org/junit4/javadoc/latest/org/junit/Before.html` or `https://junit.org/junit4/javadoc/latest/org/junit/After.html` methods.

Use `https://developer.android.com/reference/android/app/Instrumentation.html#runOnMainSync(java.lang.Runnable)` if you need to switch in and out of the UI thread within your method.