I suggest you ...

Ability to disable saving references to arguments the mock was invoked with

At my company I'm using Mock to unit test for memory leaks.

Our UI controls typically take some interface of a model, binds to its events and then updates the UI state depending on this model. When the UI gets disposed it's crucial that it unhooks completely from the model and can be garbage collected.

I unit test this by
1. Making a mock of the model interface
2. Use the mock to create the control
3. Attach a weak reference to the control
4. Dispose the control
5. Run a garbage collection
6. Check if the weak reference is alive or not.

This works great for most of our controls. However, some of our controls call the (mocked) model with a reference to the control itself.

Example:

// In my control
void UpdateSomeFunctionPropertyOnModel()
{
_model.SetSomeFunction(this.SomeFunction);
}

Even if I call _model.SetSomeFunction(null) in the Dispose-method of the control, the garbage collector will not be able to collect it.

The problem is that the mock saves the arguments whenever it gets invoked. I can see that in mock.Interceptor.actualInvocations, there is a reference to the control's SomeFunction, which hinders garbage collection of the control.

I understand that this is a feature needed to be able to vertify that calls have been made to mocked objects. In this case however, I don't need it, and it destroys the test for some of my controls. Therefore I would much appreciate if functionality was added to
a) Disable this functionality
or
b) Clear the actualInvocations list.

Kind regards,

3 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Hannes AnderssonHannes Andersson shared this idea  ·   ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base