How to spy private method
GoogleCodeExporter opened this issue · 1 comments
GoogleCodeExporter commented
Now I want to spy private method by java reflect, but when I run my code, it
tells me my spy object has not the private method, what should I do?
Object spyObject = spy(object);
setPrivateMethodAccessible(spyObject, "updateComment", parameters);
return spyObject;
Original issue reported on code.google.com by xierui.s...@gmail.com
on 18 Apr 2014 at 8:55
GoogleCodeExporter commented
private methods are only declared in the spied type, when Mockito spy an
object, it extends that type, hence it cannot see or access that private method.
Mocking private methods is test smell, a design smell, and not Object Oriented.
The code should be refactored to enable the test to alter the behavior of the
collaborating object (the one that replace the private method).
Original comment by brice.du...@gmail.com
on 21 Apr 2014 at 5:24
- Changed state: WontFix