断言项目的适当数量的清单,ES preSSO [英] Assert proper number of items in list with espresso

查看:149
本文介绍了断言项目的适当数量的清单,ES preSSO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是检查和断言,一个ListView与Android ES preSSO预期大小的最佳方式?

我写此匹配,但不太知道如何将它集成到测试。

 公共静态匹配器<视图> withListSize(最终诠释大小){
    返回新TypeSafeMatcher<视图> (){
        @覆盖公共布尔matchesSafely(最​​终查看视图){
            回报((ListView控件)视图).getChildCount()==大小;
        }        @覆盖公共无效describeTo(最终说明描述){
            description.appendText(ListView中应该有+规模+项目);
        }
    };
}


解决方案

想通了这一点。

 类匹配器{
  公共静态匹配器<视图> withListSize(最终诠释大小){
    返回新TypeSafeMatcher<视图> (){
      @覆盖公共布尔matchesSafely(最​​终查看视图){
        回报((ListView控件)视图).getChildCount()==大小;
      }      @覆盖公共无效describeTo(最终说明描述){
        description.appendText(ListView中应该有+规模+项目);
      }
    };
  }
}

如果在列表中期待一个项目,把这个在实际的测试脚本。

  OnView由(withId(android.R.id.list))检查(ViewAssertions.matches(Matchers.withListSize(1)));

What is the best way to inspect and assert that a listview is the expected size with android espresso?

I wrote this matcher, but don't quite know how to integrate it into the test.

public static Matcher<View> withListSize (final int size) {
    return new TypeSafeMatcher<View> () {
        @Override public boolean matchesSafely (final View view) {
            return ((ListView) view).getChildCount () == size;
        }

        @Override public void describeTo (final Description description) {
            description.appendText ("ListView should have " + size + " items");
        }
    };
}

解决方案

Figured this out.

class Matchers {
  public static Matcher<View> withListSize (final int size) {
    return new TypeSafeMatcher<View> () {
      @Override public boolean matchesSafely (final View view) {
        return ((ListView) view).getChildCount () == size;
      }

      @Override public void describeTo (final Description description) {
        description.appendText ("ListView should have " + size + " items");
      }
    };
  }
}

If expecting one item in the list, put this in the actual test script.

onView (withId (android.R.id.list)).check (ViewAssertions.matches (Matchers.withListSize (1)));

这篇关于断言项目的适当数量的清单,ES preSSO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆