0
votes

I find very little reason to use EasyMock, with Mockito available.

However, when I have a class with a million dependencies, I prefer annotation syntax - Mockito @Mock/@InjectMocks or EasyMock @Mock/@TestSubject.

As far as I can tell from poking around, with Mockito I have to use MockitoJUnitRunner, or MockitoAnnotations.

MockitoJUnitRunner supports field injection, but as far as I can see, the latter requires constructor/setter injection. When I need to use a different runner, and don't want to add constructors or setters to my production code for testing, I seem to be stuck with EasyMockRule.

Does Mockito provide an equivalent, to allow non-Mockito runners and field injection?

Thank you

1

1 Answers

2
votes

You can use org.mockito.junit.MockitoJunit.rule().

@Rule
public final MethodRule mockito = MockitoJunit.rule();