简体   繁体   中英

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. When I try to match that view I will get NoMatchingView exception when it's clear that view is present.

After some debugging, I've found out that inside my test class when I eval R.id.signCheckbox I'll get ID: -1000984 . Inside cause of the NoMatchingViewException you can actually read whole view hierarchy in some format. There I've found that checkbox has different ID 2131362821 . I've read the project R.java and it's also assigning 2131362821 to R.id.signCheckbox .

So when I match withId(2131362821) it's actually working. Why it's not working with R.id.signCheckbox and where that -1000984 id comes from?

It looks like the good old Invalidate/Restart/Clean/Rebuild fixed the problem.

The IDs are still negative (like -1000984) not matching the R.java IDs, but Espresso will successfully match the views.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM