titanandrews wrote:
In this case, it's a diagram. So it's quite complicated.
Eeeek. You mean you inherited code that draws a complicated diagram in
memory, without saving it to a file?
Write a unit test that draws the simplest possible diagram in memory. Then
the test calls a Save("scratch.xml") method (with nothing inside it), and
checks that "scratch.xml" now contains the simplest possible representation
of that diagram.
Make the test pass by writing something inside Save(). Write the simplest
possible thing to get the test to pass.
Now write a unit test that loads a fixed XML file, such as
"load_test_1.xml", and draws the diagram in memory. The test will assert
that Load() generates this diagram in memory.
Now write a unit test draws the simplest possible diagram in memory, and
adds one little feature, like a single child item. The test will now assert
that "scratch.xml" contains a representation of this one little feature.
Make the test pass by upgrading Save().
Repeat for the Load method (copying the new "scratch.xml" to
"load_test_2.xml").
Keep going, for each feature, until you have just enough code in Save() and
Load() to save and load only the features in the diagram that are important.
This situation is much more accessible than barfing everything in the
diagram into an XML file. You won't know what you can change, or what's
important. Tests lock all that down.
--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand