views:

152

answers:

3

VSTS 2008 (Visual Studio Team System) is coming with inbuilt Unit Testing Feature. We can add a test project to perform unit testing over the Smart device project. The problem comes when my smart device project is not using Framework 3.5 but over Framework 2.0. I strictly not to install Framework 3.5 in the device.

But this restriction is hindering me in running UnitTest application because it is using following reference:

Microsoft.VisualStudio.SmartDevice.UnitTestFramework.dll

which requires framework 3.5 in device or the emulator else it will throw an exception. I need to know if there is any way so that i can perform UnitTest over my device application within limits of Framework 2.0.

A: 

You can set your unit test project as .Net 3.5, and your smart device project as .Net 2.0.

Is there any problem in doing so?

Ngu Soon Hui
VSTS doesn't let you set the Target Framework. Second, its already as it is.
Sumeet
A: 

I do a lot of Compact Framework development and I would suggest an alternative to use the Smart Device Unit Testing that will also solve your problem.

Refactor your code so that your UI is just a View. (Ie it does nothing but call other classes.) Then put your non-UI classes under Unit test. (Just normal unit tests.)

Visual Studio will give you a warning when you first create the normal unit test project, but after that it is smooth sailing.

There are 3 reasons for doing this:

  1. Speed. It takes a lot less time to run your unit tests this way.
  2. Ease. As you have seen, getting the smart device unit testing up and working takes a bit
  3. Compatibility. By doing this you get access to tools like Rhino Mocks.
  4. You can set the target of the unit test project to be .NET 2.0

Now the drawback:

  1. You are not "really" testing your code in the NETCF environment.

While the drawback is significant, unit tests are not a substitute for "real" testing which would quickly catch any issues that would be missed by that drawback. (And really a compile should catch most issues.)

Vaccano
Code is vast.. and has been worked by many persons. We can't refactor. Is there any other way?
Sumeet
I don't know any other way myself. If it helps, this refactoring is good for the code for more than just Unit Tests. It helps separate the UI from the Business logic.
Vaccano
A: 

You must have something set up wrong or followed the wrong procedure when creating your test project.

I just re-verified this with Studio 2008 and if the assembly you are testing targets version 2.0, then when you create the unit test project, it will also target version 2.0. You must use the "Create Unit Test" wizard from the context menu to generate the Unit Tetst project.

ctacke
For normal projects like win or web. I targets 2.0 but for Unit Test framework for a device is coming with VS2008 only else, throwing following http://www.simonrhart.com/2007/12/microsoftvisualstudiosmartdevicetesthos.html
Sumeet