Wednesday, April 22, 2009

How to convert an existing Smart Device project into a Smart Device Unit Testing Project

Since I posted about Smart Device Unit Testing using the integrated Visual Studio 2008 Testing Framework, I got a couple of questions regarding how to convert an existing project to a Smart Device Unit Testing Project. Well, let me try to help with the port on this post.

1. It must be a .Net Compact Framework 3.5 project

First of all, a Smart Device Unit Testing Project is a .Net Compact Framework 3.5 Class Library project. So, you may need to upgrade your project to the latest .Net CF version (In Solution Explorer right click your project and select Upgrade Project).

2. Add Visual Studio Testing Framework References

Right click on References folder and select “Add Reference”. Switch, if you’re not already in, to the Browse tab and enter the path of the UnitTestFramework assembly for smart devices which typically is on

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.SmartDevice.UnitTestFramework.dll

3. Include the Smart Device Unit Testing TypeGuids

Open the project source code. You’ll need first to unload the project by right clicking on it and selecting "Unload Project”. Next, please right click on it again and select "Edit Project File”.
The .csproj project file is an xml file containing project definitions. Please look for the <ProjectTypeGuids> element, and replace it with the following:

<ProjectTypeGuids>{73A5A715-AF05-47af-9C33-47A864AF9AE7};{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Save the file and right click on your project again and select “Reload Project”. If Visual Studio asks for your confirmation please select Yes.

4. Add a Test Run Configuration File

Now your Smart Device project has been turned into a Smart Device Unit Testing Project. But you need to define at least one .testrunconfig file targeting the emulator or an actual device to run your tests. If you are not familiar with how to add a test run configuration file, please take a look at this post.

5. Make your tests build and start running them!

It’s time to build your code… and just run the tests on the target platform of your choice!.

Piece of cake! Isn’t it? ;)

No comments: