Announcement: NDDNUG – Automated Unit Testing

July 29, 2007

I’m going to have another chance to refine my “real world unit testing” talk. I’ll be presenting at the North Dallas .Net User Group this Wednesday (August 1) at 6:30pm. The topic will cover unit testing, dependency injection and mocks/stubs using NUnit and RhinoMocks. The talk is VERY demo intensive and should be fun as well as informative. You can sign up here to attend – the pizza is free and the talk will certainly be interesting.

UPDATE: Here are the files I used for my presentation: PowerPoint and source.

Using Embedded Resources for Unit Testing…

July 10, 2007

I’ve often had to use XML documents in my unit testing. In the past, I’ve always done a concatenation to string together a document.

Xml document concat

However, I came across a post on Haacked that lead me to a better solution, embedded resources. Basically, you add a document to your project and mark it as an “Embedded Resource” rather than “Content” in the “Build Action” attribute.

Mark resource as embedded instead of content

This will pack it into the unit testing dll and allow you to extract it from the assembly. No more missing documents causing failing tests! In my custom class, I’ve defined a method for unwrapping the resource that allows you to pass in arguments that it will use for customizing the xml nodes. I found this to be simpler than attempting to navigate the document and update the nodes although I’m guessing it may be less performant.

Unwrap Method

One thing to be sure of with this, is that you use a centralized location for the resources so that your lookup doesn’t fail. So now I’m able to write my tests such that their intent is clear and the code is clean.

Resourced Test

Although I haven’t had the need yet, I could see where this could easily grow into handling multiple types of documents but I’ll hold off on that code until I need it. 🙂