# UiThreadTest

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/test/annotation/UiThreadTest "View this page in Java")

<br />

```
@Target(value = [ElementType.METHOD, ElementType.TYPE])
@Retention(value = RetentionPolicy.RUNTIME)
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[org.junit.Test](https://junit.org/junit4/javadoc/4.12/org/junit/Test.html),[org.junit.Before](https://junit.org/junit4/javadoc/4.12/org/junit/Before.html)or[org.junit.After](https://junit.org/junit4/javadoc/4.12/org/junit/After.html)methods.

Use[runOnMainSync](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.