Android Espresso:如何断言不应显示视图

这似乎是正确的……
onView (withId (R.id.menu_delete)).check (matches (not (isdisplayed ())));

…但它抛出了这个异常:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id: com.just10.android:id/menu_delete
If the target view is not part of the view hierarchy,you may need to use Espresso.onData to load it from one of the following AdapterViews:com.github.ksoichiro.android.observablescrollview.ObservableListView{3169f0f3 VFED.VC. .F...... 0,0-480,724 #102000a android:id/list}

不应该显示断言视图的最佳方法是什么?

解决方法

我应该使用的是:
onView (withId(R.id.menu_delete)).check (doesNotExist ());

这可能特别是视图位于选项菜单中,并且可能在任何给定时间实际存在或不存在,具体取决于onCreateOptionsMenu和onPrepareOptionsMenu中的实现.

编辑

这是另一种适用于非菜单视图的方法

onView (withID(R.id.menu_delete))
 .check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)));

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...