美文网首页
Espresso之ViewAssertion

Espresso之ViewAssertion

作者: 总是一点点 | 来源:发表于2019-02-19 09:49 被阅读0次

三部曲的最后一步ViewAssertion 也就是利用所给的条件对 view 的状态进行检查,核查目标 view 当前的状态是否为预计的状态。同样的 所有的断言都应该实现了 interface ViewAssertion

public interface ViewAssertion {

  /**
   * 检查给定视图的状态(如果存在视图);打印未匹配视图原因
   *
   * @param view 如果在匹配期间有匹配结果,则为该视图,否则为空
   * @param noViewFoundException 说明未匹配到视图的原因
   */
  void check(View view, NoMatchingViewException noViewFoundException);
}

朋友们直接看注释吧,就这一个函数我也不知道怎么写了 T_T

ViewAssertion

函数 功能
doesNotExist() 断言目标 view 不存在于当前布局
matches() 断言当前 view 是否匹配指定 matcher
seletedDescendantsMatch() 目标 view 的子视图如果匹配第一个matcher,则一定匹配第二个

这里用的最多的时 matches(Matcher) ,可以根据自己的需求情况修改 Matcher 来变更断言。

LayoutAssertions

函数 功能
noEllipsizedText() 布局不包含椭圆化或剪切的TextView
noMultilineButtons() 布局中不包含具有多行文本的Button
noOverlaps 与匹配的子视图不重叠

PositionAssertions

  • isAbove(Matcher matcher)
  • isBelow(Matcher matcher)
  • isBottomAlignedWith(Matcher matcher)
  • isLeftAlignedWith(Matcher matcher)
  • isLeftOf(Matcher matcher)
  • isRightAlignedWith(Matcher matcher)
  • isRightOf(Matcher matcher)
  • isTopAlignedWith(Matcher matcher)

以上这些断言都是关于位置的,看名字就明白了,就不加以解释了。

相关文章

  • Espresso之ViewAssertion

    三部曲的最后一步ViewAssertion 也就是利用所给的条件对 view 的状态进行检查,核查目标 view ...

  • 格格老师教你在家轻松玩咖啡

    意大利咖啡(Espresso)——“Espresso”原意为“快速”,Espresso Cafe则指在瞬间提炼出来...

  • Espresso之Matcher

    只要使用了Espresso,那么你一定不会对withId(R.id.xxx)和withText(R.string....

  • Espresso之ViewAction

    Espresso的官方文档中提示,尽量使用Espresso提供的操作动作,来控制view,而且Espresso也确...

  • Android UI 测试指南之 Espresso

    关于 Espresso Espresso 是一个简单好用的 Android UI 测试框架 Espresso 主要...

  • Espresso的详细使用

    本篇详细介绍了Espresso的使用方式. Espresso 测试代码位置和静态导入 Espresso 测试代码必...

  • 初识Espresso

    本篇内容介绍了Espresso框架的基本使用. Espresso测试框架介绍 Espresso 是一个可以轻松编写...

  • Android测试之Espresso

    Espresso 测试框架提供了一组 API 来构建 UI 测试,用于测试应用中的用户流,可以编写简洁、运行可靠的...

  • Espresso之onView()&onData()

    如果你看了上一篇中对一些常用方法的介绍,想必现在已经可以对Espresso正常进行使用了,从这里开始我们开始看一些...

  • “咖啡之魂”——Espresso

    什么是Espresso? Espresso”来自意大利语,是与咖啡相关的单词,有on the spur of th...

网友评论

      本文标题:Espresso之ViewAssertion

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