orbfish
orbfish

Reputation: 7731

Mockito equivalent of EasyMockRule?

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

Upvotes: 0

Views: 210

Answers (1)

Stefan Birkner
Stefan Birkner

Reputation: 24510

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

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

Upvotes: 2

Related Questions