![](/img/trans.png)
[英]Android Kotlin Espresso asserting intended activity in the unit test is throwing error
[英]Espresso unit test case for Activity switch in android studio
我想使用Espresso編寫單元測試用例,該用例應檢查用戶是否成功從注銷頁面(活動)導航到登錄頁面。 請讓我知道是否任何一天都知道這一點。 如何檢查用戶是從活動A導航到活動B還是從一個片段導航到另一個片段。
在活動1開始,您可以按“導航”按鈕,使用intended
在它已經創建,以驗證意圖啟動咖啡。
// Click on the item that starts navigation
onView(withId(R.id.buttonToGoActivity2)).perform(click());
// Check if intent with Activity 2 it's been launched
intended(hasComponent(Activity2.class.getName()));
gradle依賴需要:
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
對於片段,您可以在導航到片段時檢查是否顯示了內部視圖
// Click on the item that starts navigation
onView(withId(R.id.buttonToShowFragment)).perform(click());
// wait for navigation delay
Thread.sleep(2000);
// Check that a view inside the fragment is shown
// Means navigaition to fragment is correct
onView(withId(R.id.viewInFragment)).check(matches(isDisplayed()));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.