Using NUnit to unit test WCF RIA Services in a Silverlight 4 App
I have recently tried using the Silverlight NUnit Project template (the one from Jamie Cansdale found here) for a Silverlight 4 project that uses WCF RIA 1.0. I seem to be close, but I still cannot get it to work.
Here's what I've done
- Create project. :)
- Change Silverlight version to 4.
- Set the WCF RIA Services Link开发者_如何学Go to my WCF RIA project.
- Make sure that all of the references (except for mscorlib) are CopyLocal=True.
- Try to run the tests.
What happens?
The test fixture setup (which contains only the line "_context = new MyContext();") dies with this exception:
1 test failed: SetUp : System.TypeInitializationException : The type initializer for 'MS.Internal.JoltHelper' threw an exception. ---
Has anyone else been able to use the template to test against WCF RIA projects?
The NUnit console doesn't support silverlight. See: http://greenicicleblog.com/2010/04/27/nunit-for-silverlight-updated/ (Search for "Is there a way to run these in nunit-console?")
You can get a Silverlight port of NUinit from google code (from link above) but then you've got to use the Silverlight Test runner as described in the first link above. This is OK for manually running the tests, but not useful in a continuous integration scenario.
The problem is that when the tests run in NUnit console, I believe it runs in the CLR, not the Silverlight runtime.
We have successfully used NUnit and NCover with some Silverlight code, but then it's because the code we were testing was compatible with the full .NET CLR.
This is also a good article that describes how to unit test Silverlight with NUnit: http://chris.59north.com/post/Introduction-to-setting-up-automated-unit-testing-in-Silverlight-with-NUnit.aspx
精彩评论