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

Test-Driven Development in Microsoft  .NET (Microsoft Professional)

Bugs That Cause Tooth Damage

Joe Bork recently wrote
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.

— Gordon Weakliem at permanent link

Amazon RSS Feeds and Prices

I don't get the whole debate on whether Amazon should put prices in it's RSS feeds. As Les Orchard and Jeff Barr pointed out in the comments to David Galbraith's post, if you don't like Amazon's RSS, you can write your own. I've created stylesheets to do RSS2 and Atom 0.3, for example, RSS 2.0 and Atom 0.3 (the dates on the Atom version are messed up, Amazon's XSLT processor doesn't like my use of document()) that include a price element. IIRC, NewsGator will yet you display this element as a column header and sort on it. This is a highly irresponsible implementation (hardcoded to USD), hacked on a lunch break, so don't go yelling at me about getting prices in GBP or EUR! All this being said, I've found that the ability to get a syndicated feed from the Amazon API is pretty uninteresting to me.

— Gordon Weakliem at permanent link