In JUnit4 android testing support library, @UiThreadTest cause the test method, @Before and @After to all run on UiThread.
This can cause quite a bit of issues because a lot of setUp actions require to be done on Instrumentation worker thread, so the viable work-around became running a lot of tests in UiThreadTestRule.runOnUiThread()
block. It can get ugly
To resolve this, we can either move the @Before/@After component that needs to run on instrumentation thread into its own separate rule. Which can escape from @UiThreadTest's control.
Another idea is we can support our own annotation or only test methods on UiThread w/o affecting @Before and @After, but this can get confusing on which annotation to use and would diverge from android's default behavior
I will look into this once JUnit4 migration is over
Comment 1 by candr...@chromium.org
, Mar 29 2017