jeudi 10 novembre 2016

Mock a ViewGroup

I'm trying to test a List Adapter and I need a mock ViewGroup :

@Mock
ViewGroup viewGroup = mock(ViewGroup.class);

@Before
public void initialization() {
    Context mockContext = mock(Context.class);
    when(viewGroup.getContext()).thenReturn(mockContext);
}

But when I try to execute the tests, a Mockito Exception is thrown telling me :

when() requires an argument which has to be 'a method call on a mock'. For example: when(mock.getArticles()).thenReturn(articles);

I don't understand why since viewGroup is actually a mock.

Aucun commentaire:

Enregistrer un commentaire