Re: Fwd: How to test an Exception marked withSerializableAttribute
"Brad Stiles" <[email protected]>
| Newsgroups | gmane.comp.windows.dotnet.nunit.user |
|---|---|
| Message-ID | <[email protected]> |
Simon Garratt <[email protected]> wrote: > Apologies for the earlier, rather lame "Please help me mail". I'd > been up since 3.20am after the darling daughter let go a startled > "Daddy!" Needless to say, she was back asleep 30 seconds later and > I was still awake come 5.20 ! Been there, done that. :) > Serialization is not an area I'm particularly familiar with. I've > come up with a plan and would appreciate feedback. I'm looking to > avoid a 'Fragile Test' so please do chip in with any comments. > Basically, I'm serializing a new instance of the exception into a > MemoryStream, resetting the position and then immediately > deserializing it. Then I perform the Asserts on the deserialized > object. That's one way, though starting with the full round-trip means you have a red test until *both* sides work completely. For "an area [you're not] particularly familiar with," that seems like an awful lot of code to write before getting green. If the serialization process produces some recognizable, verifiable, content, such as XML :), you might try coding that one up first, serialize it into a string, and test the resulting string using XPath (or, if you have it available, the really cool new LINQ to XML stuff) to make sure all of the content is there. In addition, this lets you add one piece of content at a time, and test each one of those pieces individually. Then, when serialization works, you build up deserialization the same way, one piece of content at a time, manually building the XML that is deserialized. After both of those work, and you better understand what's going on, *then* do the full round trip test. I personally have found that TDD not only helps me create more stable, robust, programs, but also gives me an easy way to learn and understand new technologies. Brad ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace