'Visual studio Debugger Copy object
I am wondering if anything 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 am thinking of something that you could put a break point in code -> right click the object -> Click "create moq into clipboard"
Then you could go to your unit test, paste the text which would paste the code to create that object with all of those properties.
I imagine this would save loads of time, and would be really useful for fixing bugs.
One of the difficult things I find with unit test is the manual process in creating the mock objects.
Solution 1:[1]
I'm a bit late to the party but I created a Visual Studio extension that does something very similar to what you're looking for. It will generate C# code to initialize an object from your visual studio debugging windows.
Here's the extension: Visual Studio Marketplace > Object Explorer
And here's an accompanying blog post: Exporting Objects from the Visual Studio Debugger
Solution 2:[2]
If you find it onerous to create mock objects, there is likely a problem with your design or the way your using mock objects. You shouldn't create mocks for simple 'value' objects - just use the actual objects in your unit tests. For more complex objects that your object-under-test interacts with, the interactions should be few, otherwise you may have excessive coupling between objects. As a rule of thumb, if it's hard to test, the design is probably wrong.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KyleMit |
| Solution 2 | Mike Stockdale |
