so after calling this onto my tests to layout the recyclerview:
recyclerView.addOnItemTouchListener(listener);
recyclerView.measure(0, 0);
recyclerView.layout(0, 0, 100, 10000);
and my OnItemTouchListener being:
listener = new RecyclerOnTouchListener(this, new RecyclerOnTouchListener.OnItemClickListener() {
@Override
public void onItemClick(View v, int position) {
Toast.makeText(this, "Sample toast", Toast.LENGTH_SHORT).show();
}
});
and i want to assert:
Assertions.assertThat(ShadowToast.getTextOfLatestToast()).isEqualToIgnoringCase("Sample Toast");
I need to simulate item clicks on the recyclerview. And what i'm doing is this:
recyclerView.findViewHolderForAdapterPosition(0).itemView.performClick();
recyclerView.performClick()
and they both return false, meaning no onclick listener in them is being called.
So how do we really test OnItemTouchListener
in recyclerview? In Robolectric?
Any help would be appreciated. Thanks!
Aucun commentaire:
Enregistrer un commentaire