Getting Started with Windows Phone 7 Unit Testing
Join the DZone community and get the full member experience.Join For Free
Testing is important and it can save you lots of time. To successfully setup a WP7 Unit Test project I recommend you to first obtain the ‘NuGet Package Manager’ Visual Studio 2010 extension, it will make it a breeze to retrieve the latest version of libraries and packages and add a reference to them.
Here is a step by step guide on how to create your test project using the testing framework kindly provided to us by Jeff Wilcox:
up Visual Studio and install NuGet if you do not have it: Tools –>
Extension Manager, look for NuGet Package Manager in the Online Gallery.
- Create a new Windows Phone Application project, do not modify it right now.
- Use NuGet to get the latest version of the Unit Test framework for WP7, you can do it in two ways:
- for the ‘Tools’ menu chose ‘Library Package Manager’ and then ‘Manage NuGet Packages for Solution’
- right click on the project you wish the package to be added to and select ‘Manage NuGet Packages’
- In the dialog that will open go to the Online section and look for ‘silverlight.unittest.wp7’
- click on ‘install’ to download and add the package to the selected project.
- it’s time to modify the test project following what’s written in the Test_Readme.txt file:
- open up the MainPage.xaml and handle the ‘Loaded’ event
- add the following line to the event to activate the test infrastructure: this.StartTestRunner();
- Done. Running the project you should see something like this:
You are now ready to write you own custom tests using a syntax and rules very similar the ones used by the MSTest suite that is already integrated in Visual Studio.
Opinions expressed by DZone contributors are their own.