![](/img/trans.png)
[英]Why is activity not launching in Android Instrumentation test (Activity Test) with espresso?
[英]Understanding results of Android Espresso instrumentation test
我在 Android Studio 中使用 Espresso 創建了一個簡單的測試。 測試運行完成並給出成功消息。
但是,我正在測試兩個 Button 視圖是否可見。 我希望看到一個按鈕可見,而另一個按鈕不可見
測試結果完全沒有提到這一點。 此測試的目標是通過 Firebase 測試實驗室在各種虛擬和真實設備上運行它並讀取測試結果!
這是在 Android Studio 上的簡單測試:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MyGraphingTest {
@Rule
public ActivityScenarioRule<MainActivity> activityRule
= new ActivityScenarioRule<>(MainActivity.class);
@Test
public void MyTestMethod(){
//some test instructions that will lead me to where the two Button views are...
//more test instructions that will hide one Button view from screen, while the other Button view remains visible.
onView(withId(R.id.recenter)).check(matches(isDisplayed()));
onView(withId(R.id.buttonGraph2)).check(matches(isDisplayed()));
}
}
所有檢查都“返回”為真,因此您的測試通過了。 否則,測試將失敗,您將看到失敗的原因。 如果您想查看有關支票的其他信息,您應該手動添加一些日志。
但是,我正在測試兩個 Button 視圖是否可見。 我希望看到一個按鈕可見,而另一個按鈕不可見
正如您發布的那樣,您的測試正在尋找要顯示的兩個視圖。 請記住,可見意味着View.VISIBILITY == VISIBLE
。 Displayed表示您可以在當前屏幕上實際看到它。 因此,如果可見視圖不在屏幕上或寬度或高度為零,則它實際上可能不會顯示。
如果你真的想測試可見性,你應該使用withEffectiveVisibility而不是isDisplayed
。
測試結果完全沒有提到這一點。
您正在測試是否顯示兩個視圖並且測試是否通過。 您希望測試“提及”什么? 既然你的測試通過了,測試中的所有假設都成立了,測試結果沒有什么可以告訴你的了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.