Showing posts with label .NET Compact Framework. Show all posts
Showing posts with label .NET Compact Framework. Show all posts

Wednesday, April 18, 2012

Smart device/.NET CF unit testing: No mocking

Seeing as the .NET Compact Framekwork does not have/support any mocking frameworks available for unit testing, here's a reference for writing your own stubs to fake out your external dependencies when unit testing smart device projects:

http://elegantcode.com/2009/04/29/unit-testingmocking-on-net-cf/

Smart device unit testing: deploying additional resources

A handy reference with different ways of deploying additional resources (e.g. sdf files) to the device/emulator for smart device unit test projects:

http://blogs.msdn.com/b/prativen/archive/2008/02/05/deployment-in-smart-device-unit-tests.aspx

Thursday, April 12, 2012

Unit testing smart device projects - TestContext error

A couple of days ago I started creating unit tests for a Windows Mobile smart device project that I have been working on in Visual Studio 2008. I generated a unit test method for one of the methods in one of the classes and attempted to run the test. This is when I ran into an error that took me several hours to solve, so hopefully posting this helps someone.

The test method failed to run due to the following error:

Error: System.ArgumentException: Object of type 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAdapterContext' cannot be converted to type 'Microsoft.VisualStudio.TestTools.UnitTesting.TestContext'


Googling the error returned results that suggested it was caused by upgrading a test project from Visual Studio 2005 format to 2008, and that the reference to the UnitTestFramework.dll was still for the old version (8.0) and required updating. This did not apply to me as I had not upgraded my test project from VS2005. So I continued searching.

After hours of searching for other causes for the error without success, I stumbled upon the following references in the smart device project:

Microsoft.WindowsMobile.dll
Microsoft.WindowsMobile.Status.dll

Visual Studio was obtaining these references from the following folder:

C:\Program Files\Windows Mobile 5.0 SDK R2\Managed Libraries

However, the smart device project's target platform was the Windows Mobile 6 Professional SDK. I didn't notice this before as I did not originally create the smart device project. So I removed the references to the two DLLs and readded them from the following folder:

C:\Program Files\Windows Mobile 6 SDK\Managed Libraries

After rebuilding the smart device project, running the test method succeeded.

Wednesday, April 27, 2011

Visual Studio Smart Device Projects build slowly

If you are developing a smart device application using either Visual Studio 2005 or 2008, you may be experiencing extremely slow build times every time you make a code change. This can be very frustrating when all you want to do is continually build, deploy and debug. It is most likely that the slow build is being caused by the platform verification task (PVT), which is a post-build task that runs by default. More information can be found here on what the PVT is and why it is required. You can however disable it temporarily as it is not required to be run every time you build your smart device application.

To disable the PVT, you can perform the following steps.
  1. Open the file %windir%\Microsoft.NET\Framework\v2.0.50727\Microsoft.CompactFramework.Common.targets (if using Visual Studio 2005) or %windir%\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.Common.targets (if using Visual Studio 2008) for editing.
  2. Go to the line which reads:
    ...
    
  3. Change it to:
    ...
    
  4. Add the SkipPlatformVerification environment variable to the system and set it to "true" (To re-enable Platform Verification set the environment variable to "false").
  5. Restart Visual Studio for the changes to take effect (If building from the command line using MSBuild, add /p:SkipPlatformVerification=true to your command line to turn off the task. You can specify the variable in the project file also, so that this information is persisted across sessions).

Source: Visual Studio For Devices blog