美文网首页
单元测试(3)-espresso基本用法

单元测试(3)-espresso基本用法

作者: lisx_ | 来源:发表于2020-03-23 16:13 被阅读0次

espresso主要用来进行view的自动化测试,大体分为三个步骤: 找view,执行动作,检查。
官方给出的一张图可以很好的概括:


espresso-cheat-sheet-2.1.0.png

其中有些ui不好寻找,需要自定义matcher,大致格式如下:

    //引用
    onData(withUserId("xxxx")).perform(click());

    private static Matcher<Object> withUserId(final String id) {
        return new BoundedMatcher<Object, UserInfo>(UserInfo.class) {

            @Override
            public void describeTo(Description description) {
                description.appendText("has UserInfo with ID: " + id);
            }

            @Override
            protected boolean matchesSafely(UserInfo item) {
                return item.getUserId().equals(id);
            }
        };
    }


谷歌官方文档: https://developer.android.google.cn/training/testing/espresso/

相关文章

网友评论

      本文标题:单元测试(3)-espresso基本用法

      本文链接:https://www.haomeiwen.com/subject/eqmwyhtx.html