This is a quick tip, because it confused me at first. But thanks to the always excellent Tim Heuer and Peter Provost (from the Visual Studio team), here is the answer:
Usual disclaimer: This is for XAML/C#. I am not sure how this works for the other programming stacks.
Creating unit tests for your WinRT application/library
- Start Visual Studio 2011.
- Create a new project.
- From the Add New Project dialog, select Unit Test Library (In the Visual C#/Windows Metro Style category). Give a name to the project and press OK.
- Either open the unit test class that was created, or create a new class. No need to select a fancy template, just create a new empty class.
- Decorate the class with a [TestClass] attribute.
- Create a public method with no parameters, and decorate it with a [TestMethod] attribute.
- Right click on the unit test project and select Add Reference from the context menu.
- In the Reference Manager, select Solution and then the project you want to write tests for. Then press Add and then Close.
You can now write your tests, using the usual Assert syntax. Here is a simple example.
var myClass =
var myClass =
Running the unit tests
To run the unit tests you just wrote, follow the steps:
- Select the menu View / Other Windows / Unit Test Explorer.
Build your application. You should now see the unit tests you wrote in the explorer window.
Press Run All to run all the unit tests.
Hopefully this quick tip will be helpful!