I have the following sample code:
@get:Rule
val activityRule = ActivityScenarioRule<KeyActivity>(intent)
@Test
fun test()
{
activityRule.scenario.onActivity {
onView(withText("some text")).check(matches(isDisplayed()))
}
}
and it produces the following error:
Method cannot be called on the main application thread (on: main)
I have tried running the code in coroutines such as:
runTest {
launch{
//code
}
}
As well as using launch<Activity>(intents), and using @UIThreadTest.
From what I've found anything running inside of onActivity{} is put onto the main thread, and the espresso tests that go inside onActivity cannot be run on the main thread. So I'm not too sure how to get around testing my activity.