tags:

views:

20

answers:

1

What is the correct way to write unittests for things like serialization/deserialization or writing and reading objects to/from a repository? Should I test if each and every property of my objects is correctly read and written? This seems like quite a lot of work when I have lots of types with lots of properties. Is this the way to go?

+2  A: 

For serialisation testing, you may want to serialise and compare vs. a canned test (i.e. a pre-serialised object that you know is correct).

So you would have to initially check that your canned serialised object is correct. From that point on, you're performing a regression test by simply comparing a byte stream / string or however your serialised object is represented. It may not tell you easily what has changed, but it will perform the primary function of a regression test and tell you something has changed.

Brian Agnew
Yeah. Version skew is probably the most likely bug to crop up when using serialization, and the "canned object" approach is a good way to test for this.
Laurence Gonsalves