This project is read-only.

Unit Testing

You may have noticed that all views and view models are given internal accessibility. That is because I believe that no functionality should be public unless it is designed to be accessed from outside of the assembly. However, this brings up a question: How can I unit test my view models? Fortunately, the .net framework provides us with a way to do this.

The InternalsVisibleToAttribute assembly attribute gives you the option of specifying that all internal code elements in the tagged assembly should be visible to the given assembly. Add the attribute to your AssemblyInfo.cs file like so:

[assembly: InternalsVisibleTo("MyAssemblyName.Tests")]

And voila, your unit tests will have access to classes and methods not ordinarily available.

Last edited Mar 26, 2011 at 10:34 AM by Mantaray, version 2


No comments yet.