views:

114

answers:

1

When using the VS2008 unit testing framework, I see the testrunConfig has an option to set the Host. If I change the Host from "Smart Device" to "Default" it appears like I can run the tests without deploying to an emulator.

I am wanting to test a library built for use on the Compact Framework, but it has nothing to do with the UI, etc. Is running it in the Default host fine? Or are there differences that would make a test actually break when run on the emulator vs. being run on my local machine? (I'm assuming that running on Default would still use the CF .Net libraries as those are the libraries that the dll to test references?)

A: 

If you change the test target to "Default" it will attempt to run the tests on the desktop. The problem there is that your tests will have references to the Smart Device test assemblies, and they won't be able to run at all. You'll get an error along the lines of this:

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

That said, I wouldn't think it would be a good idea anyway. You want your tests to run against the CF to ensure proper CF behavior. Running on the desktop doesn't do that. Additionally, there are a lot of non-UI cases where you use CF-specific stuff, like the WindowsMobile namespace or P/Invoking to coredll.dll.

Running against the emulator or a device is slow and a real bitch to debug, but they have value that offsets that.

ctacke
I must have done something different? I am able to compile and run my CF test with the Host set to Default. My test project is referencing the CF versions of the libraries.
MrJeepster
Very strange. I just verified with 2 different smart device projects and both fail the in the same way.
ctacke
I'm likely doing something quite wrong. Thanks for double-checking.
As a side note, you *can* run CF tests against the desktop assemblies using TestDriven.NET. See this: http://www.clariusconsulting.net/blogs/kzu/archive/2008/12/31/114595.aspx
ctacke