I would like to be able to step through a debugger, in particular Eclipse, on a Mockito Spy object. As an example, say I have the class to test below:
public class someClass(){
public someMethod(){
System.out.println("Begin someMethod call");
//some code in the method
System.out.println("End someMethod call");
}
}
And let's say I have a Mockito class as below:
@RunWith(MockitoJUnitRunnerclass)
public class SomeMethodTest {
@Spy SomeClass someSpiedObject;
@Test
public final void testSomeMethod(){
//some code in the test method
someSpiedObject.someMethod();
/some tests
}
The issue that I've run into is that if I set a debug breakpoint at //some code in the test method and at //some code in the method, the first breakpoint will be reached, but the second is not. I know that the code is run however as the system output is printed to the console. I know that, as a spied object, it is NOT the same code and the debugger shouldn't work. I also know that, VerboseLogging() could be used if it was a Mock object and not Spy. My real question is, how would one go about stepping through the code as if it were a normal object? Are there debugging frameworks that could help? Is there a feature of Mockito I'm not aware of? I eventually will no longer need it to be a Spy object and can simply test it, but not until the static calls are refactored.
I ran into the same problem, on IntelliJ. I am mocking only 1 of the methods in my service under test.
The only solution I have found is to put a breakpoint in my test code, and Step-Into (F7) the real method to debug the actual code. It sucks but it's the only way I've found so far.