Cannot debug Mockito / JUnit code in Eclipse, works fine with just JUnit
I've got JUnit tests that run just fine. Added Mockito to my build and I try to put a breakpo开发者_开发知识库int in my JUnit test that uses Mockito to mock out some of the public methods. When I try to run the debugger on the class, I get the error "unable to install breakpoint in XXX due to missing line number attributes. Modify compiler options to generate line number attributes." I checked my compiler and I generate line numbers is selected.
The exception you're seeing is caused by attempting to debug dynamically generated empty mock methods created by the mock() function. From your question, it looks like you actually want to be using partial mocks instead of full mocks, where only some methods are mocked and the remaining calls are delegated to the real implementation.
To create partial mocks, you should be using the spy() method instead of the mock() method. So, use
MyClass myMock = spy(new MyClass());
instead of
MyClass myMock = mock(MyClass.class);
Try by removing and re-adding your breakpoints, it might just be that a current breakpoint references an old version of a class. Just that!
Maybe this post in the Mockito group can help you.
I have the same messages (Eclipse Luna).
In spite of the large number of error messages, the debugging is still working if the debugger hits your breakpoint. You just have to click 'ok' on all of them, or disable these messages.
I think the problem originates from placing breakpoints on an extended class (mockito probably is dynamically extending the mocked classes) and Eclipse being unable to trace down the source code.
If it only happens when you use Mockito, then maybe it's because Mockito was compiled without debugger support?
Also, check that you have the same compiler settings for your test classes as for your regular code.
Happens when you put a breakpoint in a mocked method
besides this question being old I had same problem today and the solution was quite simple, but took some time to figure it out. So this may be of help to who stumbles here.
I just had some old breakpoint set and one of them was pointing to some changed code, so that the recorded breakpoint position was not good anymore.
My advice is to try to remove all the offending breakpoints and reinstall them on the current code. After a clean build, just to be sure to point to the latest binary. :)
精彩评论