android - Recyclerview Espresso 测试导致 androidx.test.espresso.PerformException
问题描述
我有下一个需要测试的 recyclerView。
public class DashboardRecyclerViewAdapter extends RecyclerView.Adapter<DashboardRecyclerViewAdapter.DashboardViewHolder> {
...typical rec view test
//Binding the data using get() method of POJO object
@Override
public void onBindViewHolder(@NonNull final DashboardViewHolder holder, int position) {
if(pad_list!=null){
final DashboardAccountItem account = pad_list.get(position);
holder.binding.accountType.setText(account.getAccountName());
....
}
.....
}
...
//View holder class, where all view components are defined
public static class DashboardViewHolder extends RecyclerView.ViewHolder {
private final DashboardAccountItemBinding binding;
public DashboardViewHolder(DashboardAccountItemBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}
我想检查 recyclerview 是否有名称为“名称 99”的项目,该项目在启动时从数据库预加载:
onView(withId(R.id.accountView)).perform(RecyclerViewActions.scrollTo (hasDescendant (withText ("name 99"))));
当我运行它时,我得到了下一个错误:
androidx.test.espresso.PerformException: Error performing 'scroll RecyclerView to: holder with view: (view is an instance of android.view.ViewGroup and has descendant matching an instance of android.widget.TextView and view.getText() with or without transformation to match: is "name 99")' on view 'view.getId() is <2131296312/com.example.recviewtestapp:id/accountView>'.
.....
at com.ashunevich.finobserver.RecyclerViewTest.scrollAndCheck(DashboardRecyclerViewTest.java:102)
///row 102 is where test situated
... 31 trimmed
Caused by: java.lang.RuntimeException: Found 0 items matching holder with view: (view is an instance of android.view.ViewGroup and has descendant matching an instance of android.widget.TextView and view.getText() with or without transformation to match: is "name 99"), but position -1 was requested.
at androidx.test.espresso.contrib.RecyclerViewActions$ScrollToViewAction.perform(RecyclerViewActions.java:361)
at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:2)
at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:22)
at androidx.test.espresso.ViewInteraction.access$100(ViewInteraction.java:1)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:2)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1139)
尽管我有一个带有文本“name 99”的“accountType”项目。
将不胜感激任何帮助。
解决方案
推荐阅读
- php - Kubernetes 集群中的 Laravel ENV 变量冲突
- c# - 将变量类型更改为/从(TreeViewEventArgs 或 TreeViewCancelEventArgs)
- android - 调用没有任何值的绑定适配器
- android - 如何在滚动视图中动态添加可滚动的水平线性布局
- python - 在python中合并两个排序的项目列表
- c# - Azure 语音服务语音转文本错误
- ms-access - 无法在 MS Access 查询的 IsError 函数中显示 NA
- amazon-web-services - 切换到其他网络时无法访问服务器
- python - 在 h5py 数据集中存储数组时,尺寸会改变吗?
- javascript - Amcharts“TypeError:this.chart.zoomToDates 不是函数”