I been searching online but I'm unable to find out how testing is made better with MVVM. I get the idea of having a viewModel which interfaces with the view but I don't know how I would write good test cases with MVVM. I have the following ViewModel in Android already:
public class ViewModel extends BaseObservable {
private long countDownTime;
private MyCountDownTimer mCountDownTimer;
private final String TAG = getClass().getSimpleName();
@Bindable
public long getCountDownTime() {
return countDownTime;
}
public void setCountDownTime(long countDownTime) {
this.countDownTime = countDownTime;
notifyPropertyChanged((int) BR.countDownTime);
Log.d(TAG,"prime tick:"+countDownTime);
}
public void startCounting(Long milli){
mCountDownTimer.restartTimer(milli);
}
}
and then I have a xml view that uses it. I also have an activity which actually binds the xml to this view. This activity looks like this:
public class MainActivity extends FragmentActivity {
CountdownBinder mCountdownBinder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
mCountdownBinder = DataBindingUtil.setContentView(this, R.layout.activity_main);
//Lets reference our textview just for fun
mCountdownBinder.tvGreen.setText("initial text");
ViewModel viewModel = ViewModel.instance();
//now tell databinding about your viewModel below
mCountdownBinder.setViewModel(viewModel);
viewModel.startCounting(200000L);
}
}
Now I'm so confused how to this makes testing better. I read about it but I need a real world example. This code is from the blog here if that matters.
Apparently I can test my unit tests easier right? Would I only test the viewModel in MVVM? What needs to be tested primarily ?