我正在尝试做一个简单的浓缩咖啡测试,它将找到第一个项目
RecyclerView没有特定标签,然后单击它.为实现这一点,我将espresso-contrib添加到这样的项目中:
RecyclerView没有特定标签,然后单击它.为实现这一点,我将espresso-contrib添加到这样的项目中:
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') { // Necessary to avoid version conflicts exclude group: 'com.android.support',module: 'appcompat' exclude group: 'com.android.support',module: 'design' exclude group: 'com.android.support',module: 'support-v4' exclude group: 'com.android.support',module: 'appcompat-v7' exclude group: 'com.android.support',module: 'support-annotations' exclude module: 'recyclerview-v7' }
并在我的测试用例中写下以下表达式:
onView(withId(R.id.sresults_list_recycler)).perform(RecyclerViewActions.actionOnHolderItem(new FirstNotSoldOutMatcher(),click()).atPosition(1));
Matcher完美运行,RecyclerView滚动到目标项目.但后来我得到错误:
java.lang.NoSuchMethodError: No virtual method findViewHolderForPosition(I)Landroid/support/v7/widget/RecyclerView$ViewHolder; in class Landroid/support/v7/widget/RecyclerView; or its super classes (declaration of 'android.support.v7.widget.RecyclerView' appears in /data/app/com.example-1/base.apk) at android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction.perform(RecyclerViewActions.java:288) at android.support.test.espresso.contrib.RecyclerViewActions$ActionOnItemViewAction.perform(RecyclerViewActions.java:232) at android.support.test.espresso.ViewInteraction$1.run(ViewInteraction.java:144) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
这看起来很奇怪.我在Google文档中读到,现在不推荐使用findViewHolderForPosition方法,但它应该仍然存在.我也在应用程序中启用了multidex,但根据文档它支持开箱即用,所以也不应该是一个问题.
你知道这个测试有什么问题吗?