I have a unit test which contains huge data that needs to compared with actual custom object. So I have to create an expected custom object and populate it with huge data, rightnow I am hard coding the expected custom object in code. There is a scenario where I have test with differenct set of data as a input for the method I am testing. Depanding on the set of data I have to get relative output which will be the actual respons (huge data). Is there any best practice for the above scenario other than hard coding expected values in code? (some thing like XML or CSV).
Share
You can create code that will serialize object using
XmlSerializer.You need to call that code when application is running and you have correct object in memory.
Save XML into the file and construct object in test from XML.
You may have several XML files that can cover different scenarios.
In my application I had code that imports data from external webservice. I generated a few XMLs for service response objects (they were huge) and use them to test my parsing logic.
Update: That trick works only for Entities objects. You cannot serialize/deserialize class that works with files or database.
Here you can find sample code.
http://www.jonasjohn.de/snippets/csharp/xmlserializer-example.htm