Is deserializing complex objects instead of creating them a good idea, in test setup?
- by Chris Bye
I'm writing tests for a component that takes very complex objects as input. These tests are mixes of tests against already existing components, and test-first tests for new features.
Instead of re-creating my input objects (this would be a large chunk of code) or reading one from our data store, I had the thought to serialize a live instance of one of these objects, and just deserialize it into test setup.
I can't decide if this is a reasonable idea that will save effort in long run, or whether it's the worst idea that I've ever had, causing those that will maintain this code will hunt me down as soon as they read it.
Is deserialization of inputs a valid means of test setup in some cases?
To give a sense of scale of what I'm dealing with, the size of serialization output for one of these input objects is 93KB. Obtained by, in C#:
new BinaryFormatter().Serialize((Stream)fileStream, myObject);