[英]Instrumentation test doesn't match view ids from hierarchy
In short, I'm trying to match view with ID like R.id.signCheckbox
using Espresso. 简而言之,我正在尝试使用Espresso将视图与像
R.id.signCheckbox
这样的ID匹配。 When I try to match that view I will get NoMatchingView exception when it's clear that view is present. 当我尝试匹配该视图时,当显示视图存在时,我将获得NoMatchingView异常。
After some debugging, I've found out that inside my test class when I eval R.id.signCheckbox
I'll get ID: -1000984
. 经过一些调试后,我发现在我的测试类中,当我评估
R.id.signCheckbox
我会得到ID: -1000984
。 Inside cause
of the NoMatchingViewException
you can actually read whole view hierarchy in some format. 在
NoMatchingViewException
内部cause
中,您实际上可以以某种格式读取整个视图层次结构。 There I've found that checkbox has different ID 2131362821
. 在那里,我发现复选框有不同的ID
2131362821
。 I've read the project R.java
and it's also assigning 2131362821
to R.id.signCheckbox
. 我已经阅读了
R.java
项目,并且它还将2131362821
分配给R.id.signCheckbox
。
So when I match withId(2131362821)
it's actually working. 因此,当我与
withId(2131362821)
匹配时,它实际上正在工作。 Why it's not working with R.id.signCheckbox
and where that -1000984
id comes from? 为什么它不能与
R.id.signCheckbox
一起使用? -1000984
id来自何处?
It looks like the good old Invalidate/Restart/Clean/Rebuild fixed the problem. 好像旧的Invalidate / Restart / Clean / Rebuild看起来修复了这个问题。
The IDs are still negative (like -1000984) not matching the R.java IDs, but Espresso will successfully match the views. ID仍为负数(如-1000984),与R.java ID不匹配,但Espresso将成功匹配视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.