I have a listview in my fragment UI that its elements set depend on status of a value that come from a viewmodel LiveData attribute.
I want to create instrumental test for the fragment which englobes 3 scenarios test case related to the value set of that attribute and I don't where to start.
My code should kind look like below :
class MyViewModel : ViewModel() {
var status = MutableLiveData("")
}
class MyFragment : Fragment() {
private lateinit var myViewModel: MyViewModel
private lateinit var myListView: ListView
override fun onAttach(context: Context) {
AndroidSupportInjection.inject(this)
super.onAttach(context)
myViewModel =
ViewModelProviders.of(this, ViewModelProvider.Factory).get(MyViewModel::class.java)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
when (myViewModel?.status) {
"status1":
setListContent(items1)
"status2":
setListContent(items2)
"status3":
setListContent(items3)
else
setListContent(items1)
}
}
private fun setListContent(itemsList: List<?>) {
myListView.adapter = MyCustomadapter(context!!, itemsList)
}
}