Thursday, May 17, 2012

Windows Phone 7 : Unit Testing (Create Test Project)

To Create Test Project in windows phone 7, you require to install NuGet and Windows Phone Test Project Templates.

It is a Visual Studio extension that makes it easy to install third-party libraries and tools in Visual Studio.

WP7Essentials library is used to create WindowsPhoneEssentials.Testing project that contains Silverlight Unit Test Framework which has been updated for use with Mango, as well as a few testing helpers.

Let’s go through Step by steps.

Step 1 :Download and  Install NuGet.

    Click To Download NuGet.
Step 2 : Download and Install Windows Phone Test Project Template.

   Click WP7 Test Project Template To Download phone test project template.

Step 3 : Create Windows Phone Test Project.

After installing NuGet and WP7 test project template, Start with creating new test project.
Open Visual studio and click on New Project.

In New Project dialog left panel select Test from Installed Template.

There are two items listed Test Project and Windows Phone Test Project as in below screen.

Select Windows Phone Test Project and click OK button.

your Project solution Explorer look like below screen.

When you build you project it gives error related to assembly missing (Microsoft.Silverlight.Testing , Microsoft.VisualStudio.TestTools.UnitTesting)

For that we have to use NuGet to get the latest versions of either Silverlight Unit Test Framework for Windows Phone (No Mango Support yet!) or Windows Phone Essentials Testing.

Step 4 : Install WindowsPhoneEssentials.Testing Package.

Click on Tools Menu and select Manage NuGet packages from Library Package Manager as in below screen.

Manage NuGet Packages Dialog will opened.

In this dialog, Search windowsphoneessentials from Search Online Textbox.
 it gives a list of packages, select WindowsPhoneEssentials.Testing item from the list and click on Install button (See below image).

it will install packages in current project, now close the dialog.

Now expand references in project, few assemblies are added into project reference (see image below).

As shown in above image, highlighted assemblies are added into reference and also one package.config file added into project.

Now Build you project, it build succeeds.
Run the Application, you testcase run within 5 seconds and you will get result (see below image).


In this way you can create you own Test Project using NuGet and WindowsPhoneEssentials Package.

No comments:

Post a Comment