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?

Saturday, August 29, 2009

Where to start

I'm going to try to document the process of creating a Silverlight web game. I like to call the various flash based games "time wasting games" because that's pretty much what they feel like.


I'm not planning on making anything better, in fact because I'm not a graphic or game designer by training, it probably won't even do a good job of getting people to wast time! What I do want to do is have a project where I can hone my C#/.NET/Silverlight skills and maybe make a game that I would like to play.

I'm starting with the SimpleShooter project that's on Codeplex and working out from there.

My first change is going to be to put together a GameWorld class that can keep track of the state of all the objects in the game. The SimpleShooter project keeps track of all the sprites in the game right inside the Page class. That's a good place to keep track of things for a small project. I like to make testable classes. I'm not a hard core TDD guy, at least not yet, but I think their philosophy does have a lot of good points and I find that the TDD code I write is usually better code that the stuff I build without a testing framework.