How to save a data structure in memory so that you can later use it in Unit test

In my code, I sometimes passed various byte arrays and the like. In addition, they can be managed objects. I would like to preserve these memory structures so that I can write test cases for concrete examples.

My standard approach is to click a breakpoint, use the debugger to find the various values, and then either update them, or insert a file or something into the unit test assembly as a resource. Sometimes this involves writing my own abstraction of the interaction of components to make my code depending on what can be updated.

Is there an easier way? I can’t imagine that this is something new. Say that you are given a fire central unit for communication. You play with him to make him create his datagrams that you want to create for your unit tests. In addition, when you encounter an error due to some undocumented way of composing your central messages, you want to record and save these examples.

Ideally, I would like to be able to record all interactions with my code, and then select and select different playback scenarios. But just getting various examples of the datagrams in memory from the debugger and returning it back to the unit test helped me a lot.

Any suggestions?

+5
2

.

, / , , . , , .

, , . , /mock . , , / , , , .

+4

, - in-memory, . Memento - , - .NET .

, . :

. .

, Decorator, . , Decorator, () , , , .

Memento Decorator, , . Memento Decorator .

, Memento Decorator , unit test, , , , , ...

+3

All Articles