mardi 26 juin 2018

How do i test android viewmodels with livedata

Help needed , First of all i've searched the net but haven't fallen on a post to address my needs

I have ViewModel class, I have Fragment that uses the ViewModel class via the ViewModelProvider, The ViewModel class has inputtext mutable livedata and list livedata

How to i use Mockito to test my UI using the viewmodel using the following example.

E.g A todo app example found here https://dukescript.com/best/practices/2015/02/16/tdd-with-dukescript.html

TodoListViewModel model = new TodoListViewModel();
assertEquals(model.getTodos().size(), 0);
model.setInputText("bu");
model.addTodo();
assertEquals(model.getTodos().size(), 0);
model.setInputText("buy milk");
model.addTodo();
assertEquals(model.getTodos().size(), 1);
assertEquals("", model.getInputText());

Aucun commentaire:

Enregistrer un commentaire