Cannot debug Mockito / JUnit code in Eclipse, works fine with just JUnit

8,437 views
Skip to first unread message

AlbertTWong

unread,
Jun 30, 2010, 10:51:08 PM6/30/10
to mockito
I've got JUnit tests that run just fine. Added Mockito to my build and
I try to put a breakpoint 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. I've googled for the obvious answers and I
can't seem to find the solution. Anyone encounter this?

Max

unread,
Jul 1, 2010, 3:31:48 AM7/1/10
to moc...@googlegroups.com
I never saw this problem before. Can you check what checkboxes do you have ticked under "Classfile Generation" in Window>Preferences>Java>Compiler.


--
You received this message because you are subscribed to the Google Groups "mockito" group.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.


Max

unread,
Jul 1, 2010, 3:32:50 AM7/1/10
to moc...@googlegroups.com
Do the same for Project specific settings.

Albert Wong

unread,
Jul 1, 2010, 3:25:01 PM7/1/10
to moc...@googlegroups.com
Using Eclipse Java EE IDE for Web Developer Helios Release 20100617

Compiler
+ Add variable attributes to generated class file
+ Add line number attributes to generated class file
+ Add source name to generated class file
+ Preserve unused local variables
+ Inline finally blocks

I didn't enable project specific compiler options.
--
Albert T. Wong  |  Technical Architect  |  ScoreBig, Inc.
c. 949.870.9664 |  f. 323.370.6775  | e. alb...@scorebig.com

szczepiq

unread,
Jul 1, 2010, 3:58:51 PM7/1/10
to moc...@googlegroups.com
Does debugging work fine on other classes, those that not use Mockito?

Cheers,
Szczepan

zero

unread,
Jul 10, 2010, 8:27:44 AM7/10/10
to mockito
Hi All,

I was facing the same problem. Please note that;
1. Debugging works for the junit test class which creates the mock
objects.
2. However, the mocked classes failed.

Here is my observation;

This failed
MkDirExecutor mockDirExecutor = mock(MkDirExecutor.class);<<<<<<<
// mock step
Step mockStep = mock(Step.class);
Mkdir mockStepConfig = mock(Mkdir.class);
String testDir = "/testDir";
mockStepConfig.setPath(testDir);
mockStep.setMkdir(mockStepConfig);
mockDirExecutor.step = mockStep;
// mock env
GathererEnvironment mockEnv = mock(GathererEnvironment.class);
StatusManager mockManager = mock(StatusManager.class);
FileResult result = (FileResult)
mockDirExecutor.executeStep(mockStep,
mockEnv, mockManager);
assertNotNull("no result", result);

This could be debugged
MkDirExecutor mockDirExecutor = new MkDirExecutor();<<<<<<<
// mock step
Step mockStep = mock(Step.class);
Mkdir mockStepConfig = mock(Mkdir.class);
String testDir = "/testDir";
mockStepConfig.setPath(testDir);
mockStep.setMkdir(mockStepConfig);
mockDirExecutor.step = mockStep;
// mock env
GathererEnvironment mockEnv = mock(GathererEnvironment.class);
StatusManager mockManager = mock(StatusManager.class);
FileResult result = (FileResult)
mockDirExecutor.executeStep(mockStep,
mockEnv, mockManager);
assertNotNull("no result", result);


Spot the difference in the line marked with <<<<<<<

I have no clue why it behaves this way, but it worked for me. Please
enlighten.

On Jul 2, 12:58 am, szczepiq <szcze...@gmail.com> wrote:
> Does debugging work fine on other classes, those that not use Mockito?
>
> Cheers,
> Szczepan
>
> On Thu, Jul 1, 2010 at 9:25 PM, Albert Wong <alb...@scorebig.com> wrote:
> > Using Eclipse Java EE IDE for Web Developer Helios Release 20100617
>
> > Compiler
> > + Add variable attributes to generated class file
> > + Add line number attributes to generated class file
> > + Add source name to generated class file
> > + Preserve unused local variables
> > + Inline finally blocks
>
> > I didn't enable project specific compiler options.
>
> > On Thu, Jul 1, 2010 at 12:32 AM, Max <maxon...@gmail.com> wrote:
>
> >> Do the same for Project specific settings.
>
> >> On Thu, Jul 1, 2010 at 8:31 AM, Max <maxon...@gmail.com> wrote:
>
> >>> I never saw this problem before. Can you check what checkboxes do you
> >>> have ticked under "Classfile Generation" in
> >>> Window>Preferences>Java>Compiler.
>
> >>> On Thu, Jul 1, 2010 at 3:51 AM, AlbertTWong <alb...@scorebig.com> wrote:
>
> >>>> I've got JUnit tests that run just fine. Added Mockito to my build and
> >>>> I try to put a breakpoint 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.   I've googled for the obvious answers and I
> >>>> can't seem to find the solution.  Anyone encounter this?
>
> >>>> --
> >>>> You received this message because you are subscribed to the Google
> >>>> Groups "mockito" group.
> >>>> To post to this group, send email to moc...@googlegroups.com.
> >>>> To unsubscribe from this group, send email to
> >>>> mockito+u...@googlegroups.com<mockito%2Bunsu...@googlegroups.com>
> >>>> .
> >>>> For more options, visit this group at
> >>>>http://groups.google.com/group/mockito?hl=en.
>
> >>  --
> >> You received this message because you are subscribed to the Google Groups
> >> "mockito" group.
> >> To post to this group, send email to moc...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> mockito+u...@googlegroups.com<mockito%2Bunsu...@googlegroups.com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/mockito?hl=en.
>
> > --
> > Albert T. Wong  |  Technical Architect  |  ScoreBig, Inc.
> > c. 949.870.9664 |  f. 323.370.6775  | e. alb...@scorebig.com
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "mockito" group.
> > To post to this group, send email to moc...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > mockito+u...@googlegroups.com<mockito%2Bunsu...@googlegroups.com>
> > .

Roberto Zagni

unread,
Dec 3, 2015, 4:49:32 AM12/3/15
to mockito, alb...@scorebig.com

This discussion is quite old, but I hit the same message today and here is just my 2cents for people who could come here in the future.

I always used Mockito in my JUnit tests and it always worked fine with the debugger, but today I got this message. :(

What sounded strange was that it was about not being able to mock some class that should not be part of the current test...
   ... so my actual problem was that I still had old breakpoints installed in Eclipse while the project code moved on and that line was not the same anymore!

TL;DR
So my 2cents are: 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!

Hope it helps!

Cleber Zarate

unread,
Jul 26, 2016, 2:58:06 AM7/26/16
to mockito
mock(MkDirExecutor.class)

will create a full mock, which won't have any debugging information as all your methods will be empty methods unless overridden.
If you're interested in mocking out only a few methods, then you need to create partial mocks by using the Spy method:

MkDirExecutor mockDirExecutor = syp(new MkDirExecutor());

This will make your exception go away.
Reply all
Reply to author
Forward
0 new messages