Silverlight NUnit Projects
I've been doing some experiments to find out if it's possible to execute NUnit on a Silverlight project. I knew that Visual Studio 2008 and Expression Blend both host Silverlight for use in the designer window. It turns out that rather than host a separate instance of the CoreCLR, the designer simply loads the Silverlight assemblies into the host runtime. This simplifies the business of creating a compatible unit testing framework considerably!
With a little bit twiddling, I've managed to tweak the 'nunit.framework' assembly so that it's compatible with Silverlight projects. In order for your tests to execute successfully, you also need to ensure that all Silverlight assemblies (except 'mscorlib') are set to 'Copy Local: True'. After this is done you can run, debug and even do code coverage on your Silverlight unit tests!
Because creating one of these projects is a fiddle to set up, I've created Silverlight NUnit Project template that does the work for you. To install the template simply open the 'SilverlightNUnitProject.vsi' file and ignore the unsigned content warning. Once installed, you will find it under the 'Visual C# / Silverlight' section of the 'New Project' dialog. You can download the template from here.
To execute one or more unit tests you should use 'Run Test(s)' rather than 'Test With > Silverlight'.
In summary you now have 3 options when testing Silverlight projects.
- For unit testing you can create a Silverlight NUnit Project and use the usual TestDriven.Net commands.
- For integration testing (within the context of a browser) you can use the Silverlight Testing Framework.
- For spelunking individual methods inside the CoreCLR you can use 'Test With > Silverlight'.
I'd be interested to hear how you get on.