【问题标题】:Testing image is not working using espresso使用 espresso 测试图像不起作用
【发布时间】:2018-05-04 05:35:04
【问题描述】:

我是使用 espresso 来测试 android 应用程序的新手。 我试图测试图像。在网上搜索时,我得到了一个链接来获取代码来测试图像。

我已经在我的编码中实现了这一点。它适用于某些图像验证。但它不适用于其他一些图像。我不知道它为什么会这样。

对于上面的代码,我遇到了类似的错误,

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with drawable from resource id: <2131230851>' doesn't match the selected view.
Expected: with drawable from resource id: <2131230851>[o2]
Got: "AppCompatImageView{id=2131296484, res-name=imgSPO2, visibility=VISIBLE, width=150, height=91, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=-1.0}"

特此附上链接,我可以在其中获取测试图像的代码。

https://github.com/dbottillo/Blog/blob/espresso_match_imageview/app/src/androidTest/java/com/danielebottillo/blog/config/DrawableMatcher.java

任何人都可以帮助我克服这个问题。

我的测试代码是,

@Test

 public void Test1_Spo2() 

{
    onView(withId(R.id.imgSPO2)).check(matches(withDrawable(R.drawable.o2)));

}

提前致谢。

【问题讨论】:

    标签: android android-espresso


    【解决方案1】:

    DrawableMatcher 类中matchesSafely 的结果可能为假。

    如果您使用 drawable.xml 文件,请确保两个图像相同。

    【讨论】:

      猜你喜欢
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多