The layout of my activity is basically this (simplified to illustrate the problem). Basically there's not much space for the ListView to appear if the device has a small screen, because other views take up all the space:
<LinearLayout orientation="vertical">
<SomeBigView
layout_width="match_parent"
layout_height="680dp"/>
<ListView
layout_width="match_parent"
layout_height="wrap_content" />
</LinearLayout>
My activity code sets up the item click listener as follows:
list.onItemClickListener = AdapterView.OnItemClickListener { _, view, _, _ ->
Snackbar.make(view, "Clicked on $view", Snackbar.LENGTH_SHORT).show()
}
My unit test taps on the first item in the list:
val controller = Robolectric.buildActivity(MainActivity::class.java)
.create().start().resume().visible()
val list: ListView = controller.get().findViewById(R.id.list)
shadowOf(list).performItemClick(0)
With Robolectric 4.2.1, my click listener is called with a non-null view.
With Robolectric 4.3, it's called with a null view.