I want to add test cases for a fragment where my UI and logical parts are mixed, and my validations also require some UI behaviors according to the business logic.
I am facing challenges in testing that fragment. So far, I have found that I can’t create an instance of the fragment class for testing, and if I want to mock it, I have to mock all of the UI elements one by one.
So, my question is how can we handle this, and what will be the strategy to add test cases?
If you can share any resources to learn it or some github repositories to look at it will be also appreciated
class TestFramgent : BaseFragment(){
//some global variables
onCreate(){}
onCreateView(){}
onViewCreated(){
//init views
// call some methods
}
//methods
private fun method1(){
includes ui + logical code
}
}
I have considered extracting the logical part and adding it to the ViewModel, but there are multiple cases where I need the UI in that logic too.