Visual Studio Object Debug Copy Object

I am wondering if something like this exists:

When debugging in visual studio, it would be really good if it had the ability to copy an object (all its properties and values) into memory. I think that you could put a breakpoint in the code -> right-click the object -> click "create moq to clipboard"

Then you can go to the unit test, insert the text that will insert the code to create this object with all these properties.

I suppose this will save a ton of time and be really useful for fixing bugs.

One of the difficult things that I find with unit test is the manual process of creating mock objects.

+6
source share
2 answers

I'm a little late to the party, but I created a Visual Studio extension that does something very similar to what you are looking for. It will generate C # code to initialize the object from the debug windows of the visual studio.

The extension can be found here: https://visualstudiogallery.msdn.microsoft.com/c6a21c68-f815-4895-999f-cd0885d8774f

Blog post with more information: http://www.omarelabd.net/exporting-objects-from-the-visual-studio-debugger/

+5
source

If you find that creating mock objects is harmful, you may have a problem with your design or the way you use mock objects. You should not create mocks for simple "value" objects - just use the actual objects in your unit tests. For more complex objects that your test object interacts with, there should be little interaction, otherwise there may be excessive communication between the objects. Generally, if it is difficult to verify, the design is probably the wrong one.

-1
source

All Articles