测试无法完成。原因:由于“ keyDispatchingTimedOut”,仪器运行失败。检查设备日志以获取详细信息

时间:2018-11-09 05:56:35

标签: android kotlin android-espresso android-testing androidx

在初始化数据库时尝试测试对话框的存在。初始化过程由LocalBroadcasts标记。

测试代码。

private var listActivity: ListActivity? = null

@get:Rule
val activityTestRule = ActivityTestRule<ListActivity>(ListActivity::class.java)

@Before
fun setUp() {
    listActivity = activityTestRule.activity
}

@Test
fun testCheckActivityNotNull() {
    Assert.assertNotNull(listActivity)
}

/**
 * Test that we show a progress dialog while database init/migration is in process.
 * Test that we remove that on db init/migration success
 */
@UiThreadTest
@Test
fun testCheckProgressBarShownOnBroadcast() {
    Assert.assertNotNull(listActivity)

    var dbIntent = Intent()
    dbIntent.putExtra(DB_INIT_STATUS, DB_INIT_START)
    dbIntent.action = DB_INIT_STATUS
    LocalBroadcastManager.getInstance(ApplicationProvider.getApplicationContext()).sendBroadcast(dbIntent)

    Espresso.onView(withText(R.string.please_wait)).check(matches(isDisplayed()))
    Espresso.onView(withText(R.string.migrating_data)).check(matches(isDisplayed()))

    Thread.sleep(5000) // keeping a waiting time to check the view

    dbIntent = Intent()
    dbIntent.putExtra(DB_INIT_STATUS, DB_INIT_END)
    dbIntent.action = DB_INIT_STATUS
    LocalBroadcastManager.getInstance(ApplicationProvider.getApplicationContext()).sendBroadcast(dbIntent)

    Espresso.onView(withText(R.string.please_wait)).check(doesNotExist())
    Espresso.onView(withText(R.string.migrating_data)).check(doesNotExist())
}

无法充分利用logcat。如果需要可以共享。

我最近从androidx.test.rule.ActivityTestRule转到了ActivityInstrumentationTestCase2,我的考试挂在了testCheckProgressBarShownOnBroadcast上。当我使用ActivityInstrumentationTestCase2

时工作正常

错误keyDispatchTimeout使我感到我没有正确进行测试。任何帮助表示赞赏。

编辑:  当我尝试与UI交互时,抛出'Instrumentation run failed due to 'keyDispatchingTimedOut''。否则,将转到ANR。 onView可能陷入僵局。

0 个答案:

没有答案