Using ObjectDumper to accelerate testing
ObjectDumper
is a nice & simple class that uses reflection to output the content of object
(including inner objects) to the console.
Andres showed it in the PDC and it’s available in the Linq
preview sample in “C:\Program Files\LINQ
Preview\Samples\ObjectDumper"
Currently it throws everything to the console, but it’s
a very simple change to make it output everything to a string and return it.
What is the connection to testing? Well, since it’s
capable of output hierarchical data, it’s a convenient way to use compare
a complex object, without going through all the properties, and sub properties,
and sub-sub-sub-sub properties, etc.
Compare:
Assert.AreEqual(
ObjectDumper.Dump(expected,5),
ObjectDumper.Dumo(actual,5));
To:
Assert.AreEqual(expected.Name, actual.Name);
Assert.AreEqual(expected.Description, actual.Description);
… similar code for every property and then going into
sub objects, etc …
What would you rather write?
Naturally, this isn’t 100% fool proof, but it can
certainly reduce the amount of time you spend comparing your objects.
Comments
Comment preview