Skip to content

Mocks not initialised correctly #89

@nmihalek

Description

@nmihalek

Hi, first off I like your library and I find it quite useful, great job!

I have found a small bug, which has a workaround but is quite odd.

When using the library with Espresso tests, mocking methods will not work if only doAnswer(...) is used.
This applies to the mocks which are injected by Dagger.
So for example in this instance the code inside doAnswer will not be executed:

@Mock
Parser injectable;

@Test
void test() {
	doAnswer(invocation -> /*some code*/)
		.when(injectable).parse(any());

	Robolectric.setupActivity().get();
}

But if we have a simple when on the same mock, everything will work as expected:

@Mock
Parser injectable;

@Test
void test() {
	doAnswer(invocation -> /*some code*/)
		.when(injectable).parse(any());
	when(injectable.getConfig()).thenReturn("");
	
	Robolectric.setupActivity().get();
}

Any idea what is happening, and if this is a known issue?

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions