Debugging Mocked Methods

Although strict XP practices, value tests more then debugging, there are many cases where you still have to debug the code base to find defects. Doing this with mocked objects can be very fishy.

Evaluating Mocked Properties

When evaluating methods and Properties in the Debugger, the Debugger Hi-Jacks the running application to run the code that evaluate the values. A mocking framework doesn’t know that you are running in the debugger and will return the mocked value. This might cause the test to fail, because of unexpected calls or different return values.

Breaking While Recording

When in Natural Mocks recording block, breaking inside the block will lead to very strange results. This is because the Hi-Jacked threads that are evaluating Properties are being recorded and mocked. The current workaround is to turn off automatic property evaluation.

Debugging Mocked Methods

When stepping into a mocked method, or putting a break point on it, you will never reach the break point. This is because the method is mocked and is never actually run. This is very confusing and I have heard some developers spending a lot of time trying to understand what is happening.


These issues have been a major feature of our coming TypeMock version and will all be solved.

  • Mocked Property and Method Evaluation will not change the test!
  • Breaking in the Recording Block will nor mess up the recording!
  • There is a visual cue that will allow you to see that the method is mocked.

Example of debugging a mocked method.


As you can see, it is very easy to see that the method is mocked and understand why you cannot step into the method.

What do you think of the visual cue?

We are thinking about adding more information to the editor

  • Return Values
  • Conditional Returns (based on arguments)
  • Different instances

What other information would you like to know while debugging?

  1. I like the visual cue, but make sure it doesn’t interfere with other add-ins that provide visual enhancements like the DevExpress CodeRush and Refactor products.

    It would be nice if you could do something in the Watch windows to let the person know that the value they’re looking at is mocked. Like putting a [mocked] next to the variable name or something.

  2. Oh, ok…
    I mistaken it with a ReSharper feature.
    My ReSharper is configured to outline blocks in a similar fashion when the cursor is placed outside the block’s brackets. It looks exactly the same.

  3. I’ve no idea. I’m no so sure your cue is bad – I just mistaken it for a ReSharper feature which looks the same.
    But that feature is only visible when the cursor is near the brackets, and your cue is visible as long as you’re inside a mocked method, so I guess it shouldn’t be confusing.

  4. Resharper put a visual cue in the left column (where the red debug spot appears)to (for instance) indicate that a method implements an interface. Why don’t you do something like that? Maybe have an ‘M’ in a circle to left of the method name.

  5. Yeah, the outlining is similar to my R#r settings as well. Using the gutter is reasonable (per glb’s comment).


Add Comment

Required fields are marked *. Your email address will not be published.