Unit Testing in .NET
I've been trying to adopt a test driven development approach,
especially for code I write for work. Having a REPL available makes
me even lazier about Unit Testing in Scheme or Python, but I've
become pretty convinced of the utility of unit testing, especially
at work where a number of people have their fingers in the code
base I work on. The latest challenge has been testing
SoapExtension and IHttpAsyncHandler extensions,
and I've developed a solution for this using Cassini and
NUnit, when I get some more time, I'll try writing it up.
For those of you new to TDD on a .NET platform, the April edition of MSDN Magazine (not available online yet) has a feature written by James Newkirk and Will Stott about Unit Testing using C# and NUnit. This article's fairly lightweight, but is a good intro to TDD. James also has an upcoming book cowritten with Alexi Vorontsov which looks really promising.
Dave Thomas also posted on his upcoming release, Pragmatic Unit Testing in C# with NUnit, so it looks like there's going to be a choice if you need a book on Unit Testing in .NET.
— Gordon Weakliem at permanent link
Bugs That Cause Tooth Damage
The kind of testing I like: "There's a crash that happens only sporadically and I don't yet have a good repro."Joe, I've got one for you. So we have a customer using our web services who occaisionally generates a request that causes the service to respond with a pretty big (128K) XML Document that the XML parser chokes on. I have a test client that I can plug the request into and get it to repro fairly consistently, about 50% of the time. But then, after a few days, no repro. And the error can change over time, the last instance we had started as
System.Xml.XmlException: This is a DTD declaration outside of a DTD. Line 3, position 118558.(never mind that there's no DTD declaration in the document) but after a day or two, the parser decided that the error was now
System.Xml.XmlException: This is an unexpected token. The expected token is '['. Line 3, position 85797.when the responses haven't changed substantially. The killer is that the document is perfectly valid; I've captured responses in Ethereal that the XML parser errors out on, but when I extract the XML document and load it up from a file, there's no error. Also, I have another test client that never will repro, the 2 differences are that the 2nd client is doing an asynchronous invocation and also adds the Authenticate: header on the initial request, rather than sending an unauthenticated request and getting a 401 to force authentication. I've found a couple instances of people reporting wierd errors like this, as well. So what do you do? I opened a support incident with MS, but they can't repro using my client, and it's understandable that there's not much they can do without a good repro case.