【问题标题】:AssertionFailedWithCauseError when executing instrumentation tests on Travis CI在 Travis CI 上执行检测测试时出现 AssertionFailedWithCauseError
【发布时间】:2019-02-17 21:55:31
【问题描述】:

我正在我的Android project 中运行基于Espresso 2.2.2 的仪器测试。当我通过 Nexus 5 手机 (Android 6.0.1) 和 Nexus 9 平板电脑 (Android 7.1.1) 等不同设备本地运行所有测试时,所有测试成功以下命令:

./gradlew testDebug connectedCheck --stacktrace -PdisablePreDex

一旦我使用这个configuration 在 Travis CI 上运行相同的任务,那么其中两个测试失败并出现令人困惑的错误消息:

CityInfoFragmentTest > renderCityInfoWithStandardZone[test(AVD) - 4.3.1] FAILED 
    android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 

    'with text: is 
    "Since May 1, 2014 only vehicles with a green sticker are allowed to drive into the low emission zone."
    ' doesn't match the selected view.

    Expected: with text: is 
    "Since May 1, 2014 only vehicles with a green sticker are allowed to drive into the low emission zone."

如您所见,实际文本与预期文本匹配!?!


我没有使用 Espresso 3.0.2,因为有一个 bug which prevents running tests on certain devices

【问题讨论】:

    标签: android travis-ci android-espresso android-testing


    【解决方案1】:

    构建日志中的1500 & 15011562 & 1563 行解释出了什么问题。这是一个sn-p:

    预期:带有文字:是“自 2014 年 5 月 1 日起,仅允许贴有绿色标签的车辆驶入低排放区。”

    得到:text=自 2014 年 5 月 1 日起,仅允许贴有绿色标签的车辆驶入低排放区。

    预期字符串以“Since”开头,但实际字符串以“As of”开头

    您是否在测试中对字符串进行硬编码?如果是这样,你不应该:)

    【讨论】:

    • 很棒的发现!看起来我 forgot to update the tests 在我引入“since”或“as of”前缀时。非常感谢。 - 关于我引用的控制台输出:看起来好像 Espresso 打印了两次 expected 文本。可能是ViewMatcher.withText() 某处的错误。你同意吗?
    • 很高兴我能帮上忙。老实说,不确定控制台输出发生了什么。
    • 在我看来,Espresso 似乎两次打印出 expected 文本,而不是首先打印 expected 文本和然后是 actual 文本,因为它在您引用的构建日志中完成。如果我有时间创建一个示例,我将检查错误的输出是否可重现,以及它是否特定于某个 Espresso 版本。
    • 同时,我检查了Google issue tracker,但可能没有在那里发现这样的问题。
    • 请记住,您使用的是旧版本的 Espresso,因此该问题可能已经修复。
    猜你喜欢
    • 2015-07-28
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 2016-05-09
    • 1970-01-01
    相关资源
    最近更新 更多