Open GoogleCodeExporter opened 8 years ago
I'm not sure if this is a bug or a feature, but it ended up that the reason for
the failures was that in my @Before SetUp() method I was calling
MockitoAnnotations.initMocks(this);
Which apparently causes the final mocking to fail. If nothing else, maybe this
pitfall could be warned against somewhere in the documentation if it can't
somehow be deprecated to prevent developers from inadvertently calling it.
I had started this project with Mockito and didn't realize this call needs to
be removed for PowerMock+Mockito.
Jeff
Original comment by glenview...@gmail.com
on 7 Jun 2011 at 3:12
It cannot be deprecated since MockitoAnnotations is Mockito code. But it could
be added to the documentation.
Original comment by johan.ha...@gmail.com
on 7 Jun 2011 at 5:53
This could go too far; I'm not even certain I would do it, but you could add an
initMocks() method to PowerMockito and mark it as deprecated. Although this
really wouldn't have saved someone in my shoes, since the dependency would have
presumably already been satisfied by Mockito.
Alternately and much preferably, if you would contribute whatever technique you
are using to eliminate the initMocks() call over to Mockito itself, I think it
would make Mockito cleaner as well.
Thanks for updating the docs!
Original comment by glenview...@gmail.com
on 7 Jun 2011 at 1:31
I don't think the first suggestions is a very good idea, I think it would be
confusing.
The second suggestion will not work very well either. Mockito already has
another way to inject mocks without using the initMocks() method (you can use
the MockitoJUnitRunner). If Mockito were to remove the initMocks() method you
couldn't run Mockito tests with a non-standard JUnit runner. What Mockito could
do is to create a JUnit Rule that injects the mocks but that will require a
JUnit version >= 4.7.
Thanks for your suggestions though! Always helpful.
Original comment by johan.ha...@gmail.com
on 9 Jun 2011 at 10:19
Thanks for considering the suggestions; I completely agree with your
responses/rejection. Since what you're saying is that equivalent behavior
seems to already exist in Mockito to avoid the initMocks() method, I'll double
check the Mockito documentation and ask them to more explicitly document the
MockitoJUnitRunner option.
Thanks,
Jeff
Original comment by glenview...@gmail.com
on 9 Jun 2011 at 1:48
Original issue reported on code.google.com by
glenview...@gmail.com
on 6 Jun 2011 at 2:30