理論上這里進行的異步操作應該和 App 里面執行的異步操作是一樣的,可以用 IdlingResource 去守護這樣一個后臺操作,但是實際使用下來,雖然 IdlingResource 已經接受到對應的異步完成回調,但是并沒有回調到被注冊的 ResourceCallback。
Espresso 用的是 Hamcrest 的語法來進行的驗證,理論上應該支持所有 Hamcrest 的寫法,但是當我們在使用 hasProperty 這個方法的時候,會發現下面這樣的錯誤。這主要是由于 Android SDK 里面并沒有完整 JDK 的庫,我們用到這部分剛好在 Android SDK 沒有。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
at org.hamcrest.beans.PropertyUtil.propertyDescriptorsFor(PropertyUtil.java:47)
at org.hamcrest.beans.PropertyUtil.getPropertyDescriptor(PropertyUtil.java:28)
at org.hamcrest.beans.HasPropertyWithValue.propertyOn(HasPropertyWithValue.java:94)
at org.hamcrest.beans.HasPropertyWithValue.matchesSafely(HasPropertyWithValue.java:81)
at org.hamcrest.TypeSafeDiagnosingMatcher.matches(TypeSafeDiagnosingMatcher.java:55)
at org.hamcrest.core.AllOf.matches(AllOf.java:27)
at org.hamcrest.DiagnosingMatcher.matches(DiagnosingMatcher.java:12)
at android.support.test.espresso.action.AdapterDataLoaderAction.perform(AdapterDataLoaderAction.java:83)
at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
|
原文轉自:http://ohmerhe.com/2017/04/18/espresso_huge_ui_test/