Monday, August 31, 2009

Testing a Silverlight Application

I wanted to get a testing framework setup early on with my project.  I'm using Visual Studio 2008 Professional and usually I just add a Test Project to my solution, then right click on a method and do the "add test" thing.  With a Silverlight 2.0 app, it doesn't work.  You get the test project, but you can't add the right assemblies to make everything work perfectly.  I was missing System.Windows, but I think that there were other things that just weren't compatible.

There is a solution though.  Some quick googling got me to http://www.jeff.wilcox.name/2008/03/silverlight2-unit-testing/ The easy option, Option #2 where you install a new test template ended withwith me saying "but I don't have the Team edition of Visual Studio."  I had to use option #1 which involves downloading the Source Code and Unit Tests for Silverlight 2 Beta from Microsoft.  Once I did that I ran the exe which unzipped the source into a temp directory.  I pulled the three DLL's listed in the article and got started with my first test. 
You need to test a failure for your tests or you might find that you have coded a test that always passes no matter what horrible code you wrote.  Here's my proof.  See all the red?

No comments:

Post a Comment